gnustep / tools-windows-msvc

Objective-C on Windows using Clang and GNUstep.
MIT License
44 stars 10 forks source link

throws error on compilation/linking #23

Closed Juff-Ma closed 1 year ago

Juff-Ma commented 1 year ago

When i try to compile the file test.m

#import <Foundation/Foundation.h>

int main(int argc, char** args){
    NSLog(@"Test");
    return 0;
}

when linkung using MinGW clang throws the following error:

$ clang `gnustep-config --objc-flags` -c test.m
In file included from test.m:1:
In file included from C:/GNUstep/x64/Debug/include/Foundation/Foundation.h:200:
In file included from C:/GNUstep/x64/Debug/include/dispatch/dispatch.h:30:
C:/GNUstep/x64/Debug/include/os/generic_win_base.h:29:13: error: typedef redefinition with different
      types ('int' vs '_mode_t' (aka 'unsigned short'))
typedef int mode_t;
            ^
C:/msys64/mingw64/include/sys/types.h:77:17: note: previous definition is here
typedef _mode_t mode_t;
                ^
1 error generated.

when using the clang-cl example it throws

LINK : fatal error LNK1181: Eingabedatei "gnustep-base.lib" kann nicht geöffnet werden. (Source file "gnustep-base.lib" could not be opened)

but it is in path, i tried adding the library path via -L but it says this argument doesn't exist.

am i doing something wrong?

Edit: the first error seems to be caused by clang, the second however i could eliminate by using clang-cl test.obj gnustep-base.lib objc.lib dispatch.lib /MDd -o test.exe /link /LIBPATH:"C:\GNUstep\x64\Debug\lib"

triplef commented 1 year ago

If you want to use clang, please make sure to not build inside a MinGW environment so that the toolchain doesn’t pick up any MinGW headers. I would recommend launching an MSYS2 shell from a Visual Studio environment (like "Visual Studio Developer Command Prompt"), e.g. by running: C:/tools/msys64/msys2_shell.cmd -defterm -here -full-path -no-start -msys

Alternatively you can forgo MSYS2 and use clang-cl in a plain VS prompt as you did. Good point about needing /LIBPATH for the linker to find the libraries. Alternatively you should also be able to specify the full paths to the .lib files instead.

triplef commented 1 year ago

I’ve updated the readme to fix the linker options. Let me know if you have any other issues or questions.