You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This project comprises a collection of scripts to build a modern GNUstep toolchain, with support for blocks and Automatic Reference Counting (ARC), using Clang and the Visual Studio toolchain with the MSVC ABI. The toolchain can then be used to integrate Objective-C code in any Windows app, without using MinGW.
6
+
This project comprises a collection of scripts to build a modern GNUstep toolchain, with support for blocks and Automatic Reference Counting (ARC), using LLVM/Clang and the Visual Studio toolchain. The toolchain can be used to integrate Objective-C code in any Windows app, including Visual Studio projects (see below), without using MinGW.
8
7
9
8
10
-
Libraries
11
-
---------
9
+
## Libraries
12
10
13
11
The toolchain currently consists of the following libraries:
14
12
@@ -23,14 +21,14 @@ The toolchain currently consists of the following libraries:
23
21
-[ICU](https://docs.microsoft.com/en-us/windows/win32/intl/international-components-for-unicode--icu-) (using system-provided DLL on Windows 10 version 1903 or later)
24
22
25
23
26
-
Installation
27
-
------------
24
+
## Installation
28
25
29
-
To install a pre-built release, download it from [the releases on GitHub](https://github.com/gnustep/tools-windows-msvc/releases) and unpack it into into `C:\GNUstep` (this location is required if you plan on using the `gnustep-config` script).
26
+
To install a pre-built release, download it from [the releases on GitHub](https://github.com/gnustep/tools-windows-msvc/releases) and unpack it into into `C:\GNUstep` (this location is only required if you plan on using the `gnustep-config` script, otherwise any location will work).
30
27
28
+
You should end up with the folders `C:\GNUstep\x64\Debug` and `C:\GNUstep\x64\Release` when using the x64 toolchain. The explanations below and the example project assume this installation location.
31
29
32
-
Using the Toolchain
33
-
-------------------
30
+
31
+
## Using the Toolchain from the Command Line
34
32
35
33
Building and linking Objective-C code using the toolchain and `clang` requires a number of compiler and linker flags.
36
34
@@ -48,7 +46,7 @@ When building in a Bash environment (like an MSYS2 shell), the `gnustep-config`
48
46
The `clang-cl` driver can also be used to build Objective-C code, but requires prefixing some of the options using the `-Xclang` modifier to pass them directly to Clang:
@@ -58,16 +56,110 @@ Specify `/MDd` for debug builds, and `/MD` for release builds, in order to link
58
56
Note that the `GNUSTEP_WITH_DLL` definition is always required to enable annotation of the Objective-C objects defined in the GNUstep Base DLL with `__declspec(dllexport)`.
59
57
60
58
61
-
Status and Known Issues
62
-
-----------------------
59
+
## Using the Toolchain in Visual Studio
60
+
61
+
The [examples/ObjCWin32](examples/ObjCWin32) folder contains a Visual Studio project that is set up with support for Objective-C.
62
+
63
+
Following are instructions to set up your own project, or add Objective-C support to an existing Win32 Visual Studio project.
64
+
65
+
### Create the Project
66
+
67
+
Launch Visual Studio, select "Create a new project", and select a project template that is compatible with C++/Win32, e.g. Console App, Windows Desktop Application, Static Library, Dynamic-Link Library (DLL). In the following we assume we are building a Console App.
68
+
69
+
Choose a name for the project and create the project. In this example, we choose ObjCHello.
70
+
71
+
### Edit the Project
72
+
73
+
#### Edit Project Properties
74
+
75
+
1. Right click the project in Solution Explorer, and select Properties.
76
+
2. In "General" change "Platform Toolset" to LLVM (clang-cl). MSVC does not support compiling Objective-C source files.
77
+
3. In "VC++ Directories" add the following for toolchain headers and libraries to be found:
78
+
* Include Directories: `C:\GNUstep\$(LibrariesArchitecture)\$(Configuration)\include`
4. Right click the project in Solution Explorer and select "Reload Project".
102
+
103
+
#### Edit Source File Properties
104
+
105
+
1. Right click on the `ObjCHello.cpp` source file and rename it to `ObjCHello.m` (or `ObjCHello.mm` for Objective-C++).
106
+
2. Right click on the `ObjCHello.m` file and select Properties.
107
+
3. In C/C++ > Advanced, clear the "Compile As" option. This tells MSBuild to not set /TP or /TC flags when compiling the file and build the file as Objective-C(++) based on the file extension.
108
+
109
+
### Add Objective-C Code and Run
110
+
111
+
Now you can start writing your Objective-C code in the `ObjCHello.m` file. You can test the setup by replacing the content of the file with:
112
+
113
+
```objective-c
114
+
#include<Foundation/Foundation.h>
115
+
116
+
intmain(int argc, char *argv[])
117
+
{
118
+
NSLog(@"Hello Objective-C");
119
+
return 0;
120
+
}
121
+
```
122
+
123
+
Place a breakpoint at the line `NSLog(@"Hello Objective-C");` and run from Visual Studio. You should see the breakpoint getting hit, and the log printed in the "Output" panel when you continue.
124
+
125
+
126
+
## Status and Known Issues
63
127
64
128
The toolchain is fully usable on x64. On x86, libdispatch is not available due to a [build error](https://bugs.swift.org/browse/SR-14314).
65
129
66
130
Note that GNUstep support for Windows is not as complete as on Unixes, and some [tests in GNUstep Base](https://github.com/gnustep/libs-base/actions/workflows/main.yml?query=branch%3Amaster) are still failing.
67
131
68
132
69
-
Prerequisites for Building
70
-
--------------------------
133
+
## Troubleshooting
134
+
135
+
### Compile Errors
136
+
137
+
* `'Foundation/Foundation.h' file not found`
138
+
Please ensure that you correctly set "Include Directories".
139
+
140
+
* `#import of type library is an unsupported Microsoft feature`
141
+
Please ensure that you have cleared the "Compile As" property of the file.
142
+
143
+
### Link Errors
144
+
145
+
* `cannot open input file 'gnustep-base.lib'`
146
+
Please ensure that you correctly set "Library Directories".
147
+
148
+
* ` unresolved external symbol __objc_load referenced in function .objcv2_load_function`
149
+
Please ensure that you added the required linking options in Linker > Input > Additional Dependencies.
150
+
151
+
* `relocation against symbol in discarded section: __start_.objcrt$SEL`
152
+
Please ensure that you include some Objective-C code in your project. (This is currently required due to a [compiler/linker issue](https://github.com/llvm/llvm-project/issues/49025) when using the LLD linker. Alternatively you can use link.exe instead of LLD.)
153
+
154
+
### Runtime Errors
155
+
156
+
* `The code execution cannot proceed because gnustep-base-1_28.dll was not found. Reinstalling the program may fix this problem.`
157
+
Please ensure that DLLs are copied to the output folder.
158
+
159
+
160
+
## Building the Toolchain
161
+
162
+
### Prerequisites
71
163
72
164
Building the toolchain require the following tools to be installed and available in the PATH. Their presence is verified when building the toolchain.
73
165
@@ -92,9 +184,9 @@ The MSYS2 installation is required to provide the Bash shell and Unix tools requ
92
184
These can be installed via Pacman inside a MSYS2 shell:
93
185
`pacman -S --needed make autoconf automake libtool pkg-config`
94
186
187
+
Please make sure that you do _not_ have `gmake` installed in your MSYS2 environment, as it is not compatible but will be picked up by the project Makefiles. Running `which gmake` in MSYS2 should print "which: no gmake in ...".
95
188
96
-
Building the Toolchain
97
-
----------------------
189
+
### Building
98
190
99
191
Run the [build.bat](build.bat) script in either a x86 or x64 Native Tools Command Prompt from Visual Studio to build the toolchain for x86 or x64.
0 commit comments