Linkage error LNK1120 while building shared library
Question:
@SibiSiddharthan Does this port support shared library, because I need to load dll through Java JNA
Build steps
cmake -DBUILD_SHARED_LIBS=1 ..
cmake --build . --config Release
Error
Generating Code...
unistd.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\src\unistd\unistd.dir\Release\unistd.lib
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/src/wchar/CMakeLists.txt
width.c
wchar.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\src\wchar\wchar.dir\Release\wchar.lib
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/src/internal/CMakeLists.txt
wmain.c
wmain.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\src\internal\wmain.dir\Release\wmain.lib
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/src/CMakeLists.txt
Creating library C:/Users/Admin/code/Tibbo/src/windows-libc/build/wlibc.lib and object C:/Users/Admin/code/Tibbo/s
rc/windows-libc/build/wlibc.exp
wmain.obj : error LNK2019: unresolved external symbol main referenced in function wmain [C:\Users\Admin\code\src\
windows-libc\build\src\wlibc.vcxproj]
C:\Users\Admin\code\src\windows-libc\build\wlibc.dll : fatal error LNK1120: 1 unresolved externals [C:\Users\Admi
n\code\src\windows-libc\build\src\wlibc.vcxproj]
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/tests/spawn/CMakeLists.txt
inherit.c
inherit-msvcrt.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\tests\spawn\inherit-msvcrt.exe
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/tests/unistd/CMakeLists.txt
kill-helper.c
kill-helper.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\tests\unistd\Release\kill-helper.exe
Building Custom Rule C:/Users/Admin/code/Tibbo/src/windows-libc/tests/spawn/CMakeLists.txt
simple.c
simple.vcxproj -> C:\Users\Admin\code\src\windows-libc\build\tests\spawn\auxilary\simple.exe
The shared build is broken currently. Needs a bit of work. Static build should work
@SibiSiddharthan Thanks for quick response. Is there any ETA to fix shared build?
or maybe you can point me out to commit where shared build was alive?
Nope. I am busy with other projects at the moment. The solution requires quite a bit of hacky stuff with CMake custom commands.
The shared build never worked to begin with only the skeleton for it was committed.
Got it. Could you point me out what CMake stuff it needs? At least I will try to learn myself
It is bit complicated. Let me explain.
With any system level C-library, programs require an entry point. In Windows it is usually CRTMainStartup() -> main(). For wlibc we override the default entry point to do initialization work. The code for this should not/never be in the shared dll. It should be statically linked and contained within the import library (i.e wlibc.lib). Currently there is no portable way to generate a dll and it's import lib and then add the initialization object file to the import lib.
Currently there is no portable way to generate a dll and it's import lib and then add the initialization object file to the import lib.
Things become more clearer, thanks again. Gues, the last question for today)
What did you mean by initialization object file ?
The compiled object of this file https://github.com/SibiSiddharthan/windows-libc/blob/main/src/internal/wmain.c