Skip to content

Commit 03483b8

Browse files
committed
Integrated USAGE into README.
1 parent 9a9362a commit 03483b8

File tree

2 files changed

+109
-152
lines changed

2 files changed

+109
-152
lines changed

README.md

+109-17
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11

2-
GNUstep Windows MSVC Toolchain
3-
==============================
2+
# GNUstep Windows MSVC Toolchain
43

54
[![CI](https://github.com/gnustep/tools-windows-msvc/actions/workflows/ci.yml/badge.svg)](https://github.com/gnustep/tools-windows-msvc/actions/workflows/ci.yml?query=branch%3Amaster)
65

7-
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.
87

98

10-
Libraries
11-
---------
9+
## Libraries
1210

1311
The toolchain currently consists of the following libraries:
1412

@@ -23,14 +21,14 @@ The toolchain currently consists of the following libraries:
2321
- [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)
2422

2523

26-
Installation
27-
------------
24+
## Installation
2825

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).
3027

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.
3129

32-
Using the Toolchain
33-
-------------------
30+
31+
## Using the Toolchain from the Command Line
3432

3533
Building and linking Objective-C code using the toolchain and `clang` requires a number of compiler and linker flags.
3634

@@ -48,7 +46,7 @@ When building in a Bash environment (like an MSYS2 shell), the `gnustep-config`
4846
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:
4947

5048
# build test.m to produce an object file test.obj
51-
clang-cl -I C:\GNUstep\x64\Debug\include -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -DGNUSTEP -DGNUSTEP_WITH_DLL -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -D_NATIVE_OBJC_EXCEPTIONS -DGSWARN -DGSDIAGNOSE /MDd /c test.m
49+
clang-cl -I C:\GNUstep\x64\Debug\include -fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -DGNUSTEP -DGNUSTEP_WITH_DLL -DGNUSTEP_RUNTIME=1 -D_NONFRAGILE_ABI=1 -D_NATIVE_OBJC_EXCEPTIONS /MDd /c test.m
5250

5351
# link object file into executable
5452
clang-cl test.obj gnustep-base.lib objc.lib dispatch.lib /MDd -o test.exe
@@ -58,16 +56,110 @@ Specify `/MDd` for debug builds, and `/MD` for release builds, in order to link
5856
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)`.
5957

6058

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`
79+
* Library Directories: `C:\GNUstep\$(LibrariesArchitecture)\$(Configuration)\lib`
80+
4. Set required preprocessor definitions in C/C++ > Preprocessor > Preprocessor Definitions:
81+
`GNUSTEP;GNUSTEP_WITH_DLL;GNUSTEP_RUNTIME=1;_NONFRAGILE_ABI=1;_NATIVE_OBJC_EXCEPTIONS`
82+
5. Add required compiler options in C/C++ > Command Line > Additional Options:
83+
`-fobjc-runtime=gnustep-2.0 -Xclang -fexceptions -Xclang -fobjc-exceptions -fblocks -Xclang -fobjc-arc`
84+
Leave out the last option if you don't want to use Automatic Reference Counting (ARC).
85+
6. Link required libraries in Linker > Input > Additional Dependencies:
86+
`gnustep-base.lib;objc.lib;dispatch.lib`
87+
88+
#### Edit Project File
89+
90+
1. Right click the project in Solution Explorer and select "Unload Project".
91+
2. Double click on the project again and to open the raw vcxproj file.
92+
3. Above the last line `</Project>` add the following to copy the GNUstep DLLs to the output directory.
93+
```
94+
<ItemGroup>
95+
<Content Include="C:\GNUstep\$(LibrariesArchitecture)\$(Configuration)\bin\*.dll">
96+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
97+
<TargetPath>%(Filename)%(Extension)</TargetPath>
98+
</Content>
99+
</ItemGroup>
100+
```
101+
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+
int main(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
63127
64128
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).
65129
66130
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.
67131
68132
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
71163
72164
Building the toolchain require the following tools to be installed and available in the PATH. Their presence is verified when building the toolchain.
73165
@@ -92,9 +184,9 @@ The MSYS2 installation is required to provide the Bash shell and Unix tools requ
92184
These can be installed via Pacman inside a MSYS2 shell:
93185
`pacman -S --needed make autoconf automake libtool pkg-config`
94186
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 ...".
95188
96-
Building the Toolchain
97-
----------------------
189+
### Building
98190
99191
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.
100192

USAGE.md

-135
This file was deleted.

0 commit comments

Comments
 (0)