gnustep / tools-make

The makefile package is a simple, powerful and extensible way to write makefiles for a GNUstep-based project.
https://www.gnustep.org/
GNU General Public License v3.0
28 stars 43 forks source link

While Configuring GNUmake its unable to find libobjc #26

Closed abhi-varma202 closed 2 years ago

abhi-varma202 commented 2 years ago

I'm trying to build a gnustep DLL on windows. I have first built objc.dll file following the instructions mention in GNU-Wiki using the libobjc2 source code and I started configuring the gnumake. while configuring its showing the following things:

checking for libobjc... no
checking for domains containing libraries libobjc.a, libobjc.so, libobjc.dll.a, libobjc-gnu.dylib, objc.lib... (none)
checking for domains containing headers objc/objc.h... (none)
checking for custom shared objc library domain...
checking whether objc has thread support... no
checking whether Objective-C++ is supported... yes
checking whether we should use ARC... not requested by user
checking for the flag to use to do partial linking... -r
checking for the GCC version... 11.2
checking for __objc_load... no
checking whether runtime library supports the gnustep-2.0 ABI... no
checking for runtime ABI... gcc
checking whether the compiler supports native ObjC exceptions... no
checking if the compiler supports autodependencies... yes: gcc version is 11.2 >= 3.0

The above command line output shows its couldn't find the libobjc and the compiler we are using doesn't support native objc exception. I want to configure make with libojc and with native objc exception support. Any help is much appreciated?

triplef commented 2 years ago

libobjc2 requires Clang, but doesn’t currently support MinGW (https://github.com/gnustep/libobjc2/pull/190).

If you’re open to using the MSVC toolchain instead of MinGW you could use this project instead: https://github.com/gnustep/tools-windows-msvc

abhi-varma202 commented 2 years ago

@triplef is there any step by step guide as to how to install libobjc and build GNUStep on windows? I have the libobjc.dll with me I just need to know how to install libobjc and how can I configure and build gnustep make and base.

triplef commented 2 years ago

If you’re ok with not using MinGW then yes: https://github.com/gnustep/tools-windows-msvc#building-the-toolchain

Alternatively you can just download the pre-built binaries: https://github.com/gnustep/tools-windows-msvc#installation

abhi-varma202 commented 2 years ago

@triplef How can I build gnustep without ARC and with native exception support using this tool chain? Is there an option that I have to give when building it?

triplef commented 2 years ago

The toolchain supports ARC, but you can decide whether you want to build your own code with or without ARC using the -fobjc-arc compiler flag. Just don’t add it when you want to build without ARC.

abhi-varma202 commented 2 years ago

@triplef I tried building my code using pre-built binaries via command line and I'm getting the following error. image

Its also not recognizing the native exception handling in objective c. Like the NS_DURING macro. why am I getting this errors and how can I resolve it.

triplef commented 2 years ago

Sounds like you are not setting the right compiler flags. Please follow the instructions here: https://github.com/gnustep/tools-windows-msvc#using-the-toolchain-from-the-command-line

abhi-varma202 commented 2 years ago

@triplef I just ran the following command for my file and it threw me this error. image

just to let u know I'm using msys2 mingw 64bit image

triplef commented 2 years ago

The clang you’re using is probably the one from MinGW, not the standard Windows one required for this setup. You’ll want to use a non-MinGW MSYS2 shell (the first one listed here), launched inside a Visual Studio environment (e.g. the "x64 Native Tools Command Prompt for VS") by running something like this: msys2_shell -defterm -no-start -msys2 -full-path

Running clang --version should show the MSVC target, not MinGW:

clang --version
clang version 12.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\Llvm\x64\bin
abhi-varma202 commented 2 years ago

@triplef This has resolved that error. Now I'm facing another error where I'm trying to generate a dll for my code. Its showing the following error. image

Any idea why this is happening. i couldn't any article for this error in google.

image Why is it expecting ';' after WINAPI

triplef commented 2 years ago

I’m guessing there’s some other error in Test.m causing this. Can you attach the whole file?

abhi-varma202 commented 2 years ago

I was trying to create empty dll just to see whether is compiling or not

#import <Foundation/Foundation.h>

BOOL WINAPI DllMain(
    HINSTANCE hinstDLL,  // handle to DLL module
    DWORD fdwReason,     // reason for calling function
    LPVOID lpReserved )  // reserved
{
    // Perform actions based on the reason for calling.
    switch( fdwReason ) 
    { 
        case DLL_PROCESS_ATTACH:
         // Initialize once for each new process.
         // Return FALSE to fail DLL load.
            break;

        case DLL_THREAD_ATTACH:
         // Do thread-specific initialization.
            break;

        case DLL_THREAD_DETACH:
         // Do thread-specific cleanup.
            break;

        case DLL_PROCESS_DETACH:
         // Perform any necessary cleanup.
            break;
    }
    return TRUE;  // Successful DLL_PROCESS_ATTACH.
}
triplef commented 2 years ago

Maybe WINAPI is not defined? Not sure if Foundation includes the right headers. You could try including windows.h or just use __stdcall instead.

abhi-varma202 commented 2 years ago

@triplef I have run the following command to create the dll.

clang -shared -v `gnustep-config --base-libs` -ldispatch -o Test.dll Test.o

and its throwing me the following error

clang version 11.0.0 (https://github.com/msys2/MSYS2-packages ca391a3660d17cdee1e94d5afd2e72a4f750cddb)
Target: x86_64-pc-windows-msys
Thread model: posix
InstalledDir: /usr/bin
 "/usr/bin/x86_64-pc-msys-gcc" -shared -v -fuse-ld=lld -fexceptions -fobjc-runtime=gnustep-2.0 -fblocks -L/home/M1060999/GNUstep/Library/Libraries -L/c/GNUstep/x64/Debug/lib -m64 -o Test.dll -lgnustep-base -lobjc -lws2_32 -ladvapi32 -lcomctl32 -luser32 -lcomdlg32 -lmpr -lnetapi32 -lkernel32 -lshell32 -lmsvcrtd -lvcruntimed -lucrtd -ldispatch Test.o
Using built-in specs.
COLLECT_GCC=/usr/bin/x86_64-pc-msys-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-msys/11.2.0/lto-wrapper.exe
x86_64-pc-msys-gcc: error: unrecognized command-line option ‘-fobjc-runtime=gnustep-2.0’
x86_64-pc-msys-gcc: error: unrecognized command-line option ‘-fblocks’
Target: x86_64-pc-msys
Configured with: /c/S/gcc/src/gcc-11.2.0/configure --build=x86_64-pc-msys --prefix=/usr --libexecdir=/usr/lib --enable-bootstrap --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --with-arch=x86-64 --with-tune=generic --disable-multilib --enable-__cxa_atexit --with-dwarf2 --enable-languages=c,c++,fortran,lto --enable-graphite --enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm --enable-libquadmath --enable-libquadmath-support --disable-libssp --disable-win32-registry --disable-symvers --with-gnu-ld --with-gnu-as --disable-isl-version-check --enable-checking=release --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible --enable-libstdcxx-filesystem-ts
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.0 (GCC)
clang: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
triplef commented 2 years ago

Looks like clang trying to use the gcc you have installed inside mys2 for linking for some reason (even though -fuse-ld=lld should make it use lld). Maybe try uninstalling gcc in MSYS.

abhi-varma202 commented 2 years ago

@triplef while uninstalling gcc its saying

checking dependencies...
error: failed to prepare transaction (could not satisfy dependencies)
:: removing gcc breaks dependency 'gcc' required by clang

Even in the website its saying clang is dependent on gcc (here)

And also looking at the error output -L/home/M1060999/GNUstep/Library/Libraries this path doesn't exist.

triplef commented 2 years ago

You should usually not have any compilers installed inside the MSYS subsystem (only inside MinGW, see here for the differences). Please uninstall both clang and gcc (clang is also the wrong one as indicated by the x86_64-pc-windows-msys target).

abhi-varma202 commented 2 years ago

@triplef So which clang should i use?

triplef commented 2 years ago

Either the one from Visual Studio, or you can install the one from releases.llvm.org. The MSYS and MinGW ones do not produce normal Windows binaries.

triplef commented 2 years ago

Alternatively if you don’t want to change your MSYS/MinGW environment it might be easier to use clang-cl directly from a Visual Studio shell as described in the readme.

abhi-varma202 commented 2 years ago

@triplef I tried the following command in visual studio developer powershell

clang-cl -I C:\GNUstep\x64\Release\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 /MD /c Test.m

and this is giving the following error

clang-cl: error: no such file or directory: '.0'
triplef commented 2 years ago

I’ve never tried in PowerShell, could this be causing this? Can you try in a normal Visual Studio CMD?

abhi-varma202 commented 2 years ago

@triplef Running the command on visual studio cmd worked... any idea what the command is for generating DLL in clang-cl ?

triplef commented 2 years ago

clang-cl has the same options as the MSVC compiler cl, so this should help: https://stackoverflow.com/a/2220213/1534401

abhi-varma202 commented 2 years ago

@triplef So just linking the lib files in the following commands are enough or do i need to include any other lib files like clang or vs?

clang-cl test.obj gnustep-base.lib objc.lib dispatch.lib /MDd -o test.exe

If just the above lib files are enough then when I use my test.dll for some other application do I have to also use the gnustep-base.dll , objc.dll, dispatch.dll ?

triplef commented 2 years ago

Yes your exe will need to be able to load the GNUstep DLLs.

triplef commented 2 years ago

I’m going to mark this as resolved, but please feel free to open issues against the tools-windows-msvc repo if applicable, or otherwise the discuss-gnustep mailing list is also a good place to get help.