Skip to content

Commit f226bdb

Browse files
committed
For gnustep-config bash script to be invoked properly by execute_process() under GNUstep shell on Windows, the ${GNUstepConfig} call must preceded by sh. Otherwise, execute_process() fails, leading to objc_def_flags and objc_def_link_flags being empty, with RESULT_VARIABLE containing : %1 is not a valid win32 application. This was the behaviour using GNUstep shell from MSYS version 0.30 downloaded from http://www.gnustep.org/windows/installer.html and it comes with GCC 4.6.1.
2 parents 47fae0a + 40c223d commit f226bdb

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

BUILD-GNUSTEP-WINDOWS.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
On Windows, using GNUstep shell and CMake, the build fails at link-time with the following type of error :
2+
3+
```
4+
undefined reference to objc_get_class
5+
```
6+
7+
The executed command by CMake is the following :
8+
9+
```
10+
/C/GNUstep/bin/gcc.exe -Wl,--enable-auto-import -shared-libgcc -fexceptions -fgnu-runtime -L/usr/home/user/GNUstep/Library/Libraries -L/GNUstep/Local/Library/Libraries -L/GNUstep/System/Library/Libraries -lgnustep-base -lobjc -lws2_32 -ladvapi32 -lcomctl32 -luser32 -lcomdlg32 -lmpr -lnetapi32 -lm -I. -Wl,--whole-archive CMakeFiles/mulle-xcode-to-cmake.dir/objects.a -Wl,--no-whole-archive -Wl,--whole-archive libmullepbx.a -Wl,--no-whole-archive -o mulle-xcode-to-cmake.exe -Wl,--out-implib,libmulle-xcode-to-cmake.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/mulle-xcode-to-cmake.dir/linklibs.rsp
11+
```
12+
13+
As we can see, gcc is called with the linked libraries appearing first (-l...), then the sources appearing after them (.a).
14+
This leads to the libraries not being linked, as the symbols in them are not yet encountered.
15+
Using ```-Wl,--no-as-needed``` does not fix the problem.
16+
17+
The following manual solution fixes the issue :
18+
19+
1 / Run CMake from the build directory:
20+
21+
```
22+
i.e. mkdir build && cd build
23+
cmake -G"MSYS Makefiles" .. -Wno-dev -DCMAKE_VERBOSE_MAKEFILE=ON
24+
```
25+
26+
2 / Go to CMakeFiles/mulle-xcode-to-cmake.dir in the build directory
27+
28+
3 / Open build.make
29+
30+
4 / Find the last gcc call. Make sure to have .a appear before -l, something like the following :
31+
32+
```
33+
/C/GNUstep/bin/gcc.exe -Wl,--whole-archive CMakeFiles/mulle-xcode-to-cmake.dir/objects.a -Wl,--no-whole-archive -Wl,--whole-archive libmullepbx.a -Wl,--no-whole-archive -Wl,--enable-auto-import -shared-libgcc -fexceptions -fgnu-runtime -L/usr/home/user/GNUstep/Library/Libraries -L/GNUstep/Local/Library/Libraries -L/GNUstep/System/Library/Libraries -lgnustep-base -lobjc -lws2_32 -ladvapi32 -lcomctl32 -luser32 -lcomdlg32 -lmpr -lnetapi32 -lm -I. -o mulle-xcode-to-cmake.exe -Wl,--out-implib,libmulle-xcode-to-cmake.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles/mulle-xcode-to-cmake.dir/linklibs.rsp
34+
```
35+
36+
5 / Open linklibs.rsp and delete libmullepbx.a
37+
38+
6 / Now, call ```make```

CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,21 @@ if( NOT GNUSTEP)
105105
find_library( FOUNDATION_LIBRARY Foundation)
106106
message( STATUS "FOUNDATION_LIBRARY is ${FOUNDATION_LIBRARY}")
107107
else()
108+
109+
# Without this, execute_process() does not work under GNUstep shell on Windows
110+
# => objc_def_flags and objc_def_link_flags are empty
111+
# => RESULT_VARIABLE contains "%1 is not a valid win32 app"
112+
if(WIN32)
113+
set(EXECUTE_PROCESS_PRECOMMAND "sh")
114+
endif()
115+
108116
find_program(GNUstepConfig "gnustep-config")
109117
if(GNUstepConfig)
110118
message(STATUS "Using GNUstep (${GNUstepConfig})")
111-
execute_process(COMMAND "${GNUstepConfig}" "--objc-flags"
119+
execute_process(COMMAND ${EXECUTE_PROCESS_PRECOMMAND} "${GNUstepConfig}" "--objc-flags"
112120
OUTPUT_VARIABLE objc_def_flags
113121
OUTPUT_STRIP_TRAILING_WHITESPACE)
114-
execute_process(COMMAND "${GNUstepConfig}" "--base-libs"
122+
execute_process(COMMAND ${EXECUTE_PROCESS_PRECOMMAND} "${GNUstepConfig}" "--base-libs"
115123
OUTPUT_VARIABLE objc_def_link_flags
116124
OUTPUT_STRIP_TRAILING_WHITESPACE)
117125
set(objc_flags "${objc_def_flags}")

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ platforms it is suggested to install a recent clang version (5 or later) and you
4545
will need libobjc and the gnustep-base developer package, both from GNUstep (or another
4646
implementation of the ObjC runtime and the Foundation library).
4747

48+
On Windows, it is a bit tricky : please refer to this little guide [here](https://github.com/ElMostafaIdrassi/mulle-xcode-to-cmake/blob/release/BUILD-GNUSTEP-WINDOWS.md)
49+
4850

4951
## Usage
5052

@@ -58,10 +60,10 @@ Options:
5860
-d : create static and shared library
5961
-f : suppress Foundation (implicitly added)
6062
-i : print global include_directories
61-
-l <lang> : specify language (c,c++,objc) for mulle-configuration (default: objc)
62-
-m : include mulle-configuration (affects boilerplate)
63+
-l <lang> : specify project language (c,c++,objc) (default: objc)
6364
-n : suppress find_library trace
6465
-p : suppress project
66+
-P <prefix> : prefix filepaths
6567
-r : suppress reminder, what generated this file
6668
-s <suffix> : create standalone test library (framework/shared)
6769
-t <target> : target to export
@@ -262,3 +264,11 @@ See the [RELEASENOTES.md](RELEASENOTES.md) for what has changed.
262264
### Author
263265

264266
Coded by Nat!
267+
268+
269+
### Contributors
270+
271+
* [@RJVB](https://github.com/RJVB) GNUstep
272+
* [@ElMostafaIdrassi](https://github.com/ElMostafaIdrassi) GNUstep WIN
273+
* [@saxbophone](https://github.com/saxbophone) Bugreports
274+

0 commit comments

Comments
 (0)