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

Using Zig as C compiler for a shared library leads to undefined symbol: _DllMainCRTStartup #3237

Closed
nxrighthere opened this issue Sep 15, 2019 · 6 comments
Milestone

Comments

@nxrighthere
Copy link

The command: zig build-lib --c-source test.c --library c -dynamic -target x86_64-windows-gnu leads to lld: error: <root>: undefined symbol: _DllMainCRTStartup error. Compilation of static library seems to work fine.

@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Sep 16, 2019
@andrewrk andrewrk added this to the 0.5.0 milestone Sep 16, 2019
@FireFox317
Copy link
Contributor

FireFox317 commented Sep 17, 2019

Looking at all the options that can be provided for lld-link (linker for windows), I think the option -NOENTRY has to be added to the linker. This is what the help mentions:

-NOENTRY      Don't add reference to DllMainCRTStartup; only valid with /dll

Passing this option to the linker does indeed solve the issue.

Edit: According to the windows docs, that creates a resource-only DLL that contains no executable code. So probably not the correct solution then

@andrewrk
Copy link
Member

@FireFox317 I think that's a good way to go. However I also think there is a regression. If you grep std lib for DllMainCRTStartup you can see there is something that was supposed to be provided. I think that mess can be removed in favor of comptime logic in std/special/start.zig.

@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 26, 2019
andrewrk added a commit that referenced this issue Feb 17, 2020
@andrewrk andrewrk added the stage1 The process of building from source via WebAssembly and the C backend. label Feb 17, 2020
@andrewrk andrewrk added os-windows and removed bug Observed behavior contradicts documented or intended behavior labels Mar 22, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Mar 22, 2020
@andrewrk
Copy link
Member

Hmm I'm not sure if this is a bug actually. I think you're supposed to define DllMainCRTStartup in your C code.

@daurnimator
Copy link
Collaborator

Related: #3000

@nxrighthere
Copy link
Author

nxrighthere commented Apr 27, 2020

@andrewrk Isn't it against using Zig as C compiler idea, if I don't need to do that with GCC/Clang/MSVC?

@zhaozg
Copy link
Contributor

zhaozg commented Oct 1, 2020

ref: #6482

zhaozg added a commit to zhaozg/zig that referenced this issue Oct 11, 2020
@andrewrk andrewrk removed the stage1 The process of building from source via WebAssembly and the C backend. label Oct 17, 2020
zhaozg added a commit to zhaozg/zig that referenced this issue Oct 18, 2020
zhaozg added a commit to zhaozg/zig that referenced this issue Oct 26, 2020
zhaozg added a commit to zhaozg/zig that referenced this issue Oct 26, 2020
zhaozg added a commit to zhaozg/zig that referenced this issue Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants