windows-libc icon indicating copy to clipboard operation
windows-libc copied to clipboard

Linkage error LNK1120 while building shared library

Open devaskim opened this issue 1 year ago • 8 comments

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

devaskim avatar Aug 08 '24 11:08 devaskim

The shared build is broken currently. Needs a bit of work. Static build should work

SibiSiddharthan avatar Aug 08 '24 11:08 SibiSiddharthan

@SibiSiddharthan Thanks for quick response. Is there any ETA to fix shared build?

devaskim avatar Aug 08 '24 11:08 devaskim

or maybe you can point me out to commit where shared build was alive?

devaskim avatar Aug 08 '24 11:08 devaskim

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.

SibiSiddharthan avatar Aug 08 '24 11:08 SibiSiddharthan

Got it. Could you point me out what CMake stuff it needs? At least I will try to learn myself

devaskim avatar Aug 08 '24 11:08 devaskim

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.

SibiSiddharthan avatar Aug 08 '24 11:08 SibiSiddharthan

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 ?

devaskim avatar Aug 08 '24 11:08 devaskim

The compiled object of this file https://github.com/SibiSiddharthan/windows-libc/blob/main/src/internal/wmain.c

SibiSiddharthan avatar Aug 08 '24 12:08 SibiSiddharthan