Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined symbol: _DllMainCRTStartup when I use zig build-lib --dynamic to generate dynamic library on windows #7065

Open
waruqi opened this issue Nov 11, 2020 · 3 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-windows
Milestone

Comments

@waruqi
Copy link

waruqi commented Nov 11, 2020

example project: https://github.com/xmake-io/xmake/tree/master/tests/projects/zig/shared_library

We can download xmake-latest.win64.exe install package to install xmake (dev version) from https://github.com/xmake-io/xmake/actions/runs/355512412

Then test this problem. (zig 0.7.0)

$ xmake f --zc=y:\zig\zig.exe
$ xmake -rv
[ 37%]: compiling.release src\main.zig
y:\zig\zig.exe build-obj -target x86_64-windows-msvc -O ReleaseFast -femit-bin=build\.objs\test\windows\x64\release\src\main.zig.obj src\main.zig
[ 50%]: compiling.release src\test.zig
y:\zig\zig.exe build-obj -target x86_64-windows-msvc -fPIC -O ReleaseFast -femit-bin=build\.objs\testlib\windows\x64\release\src\test.zig.obj src\test.zig
[ 62%]: linking.release testlib.dll
y:\zig\zig.exe build-lib -dynamic -fPIC -target x86_64-windows-msvc --strip -femit-bin=build\windows\x64\release\testlib.dll build\.objs\testlib\windows\x64\release\src\test.zig.obj
error: lld: error: <root>: undefined symbol: _DllMainCRTStartup
error: LLDReportedFailure
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-windows frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Nov 11, 2020
@andrewrk andrewrk added this to the 0.7.1 milestone Nov 11, 2020
@alexnask
Copy link
Contributor

alexnask commented Nov 11, 2020

This is quite tricky to solve.
One solution could be to add an empty module to the compilation when targetting a windows shared library with no zig file in the inputs.
This way, the start.zig code with generate and export the _DllMainCRTStartup symbol, however we don't know that the symbol is necessarily missing from the object files so start.zig would have to be modified to export it with weak linkage.
Maybe I'm missing some simpler solution, I will look into clang and LLD to see how they handle the same issue with -nostdlib.

@andrewrk
Copy link
Member

This is another example where it would work if you gave build-lib source files instead of objects. This is an enhancement issue to support creating a special kind of object.

@andrewrk andrewrk modified the milestones: 0.7.1, 0.9.0 Dec 11, 2020
@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. and removed bug Observed behavior contradicts documented or intended behavior labels Dec 11, 2020
@waruqi
Copy link
Author

waruqi commented Dec 12, 2020

This is another example where it would work if you gave build-lib source files instead of objects. This is an enhancement issue to support creating a special kind of object.

If I don’t pass the zig source files, can I just set additional linker flags to solve this problem?

@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-windows
Projects
None yet
Development

No branches or pull requests

3 participants