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

fail zig build-lib -target x86_64-windows-gnu -dynamic ... #6482

Closed
zhaozg opened this issue Oct 1, 2020 · 2 comments
Closed

fail zig build-lib -target x86_64-windows-gnu -dynamic ... #6482

zhaozg opened this issue Oct 1, 2020 · 2 comments
Labels
os-windows zig cc Zig as a drop-in C compiler feature

Comments

@zhaozg
Copy link
Contributor

zhaozg commented Oct 1, 2020

zig version output 0.6.0+4eb390b15

uname -a output

Darwin zhaozgMBP 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

a_dll.c

#include <windows.h>

BOOL WINAPI DllMain(
    HINSTANCE _hinstDLL,  // handle to DLL module
    DWORD _fdwReason,     // reason for calling function
    LPVOID _lpReserved)   // reserved
{
    return TRUE; // Successful.
}

WINAPI int Test(void)
{
  return 1;
}

run zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -ofmt=pe -lc output

error(compilation): clang failed with stderr: /usr/local/lib/zig/libc/mingw/crt/crtdll.c:213:21: error: unknown type name '_PVFV'
/usr/local/lib/zig/libc/mingw/crt/crtdll.c:215:12: warning: implicit declaration of function '_register_onexit_function' is invalid in C99 [-Wimplicit-function-declaration]
/usr/local/lib/zig/libc/mingw/crt/crtdll.c:215:39: error: use of undeclared identifier 'atexit_table'
/usr/local/lib/zig/libc/mingw/crt/crtdll.c:215:54: error: use of undeclared identifier '_onexit_t'

error(compilation): /usr/local/lib/zig/libc/mingw/crt/crtdll.c:1:1: unable to build C object: clang exited with code 1

error: unable to build mingw-w64 CRT file: BuildingLibCObjectFailed

run zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -ofmt=pe
output

error(compilation): clang failed with stderr: a_dll.c:1:10: fatal error: 'windows.h' file not found

a_dll.c:1:1: error: unable to build C object: clang exited with code 1
@zhaozg
Copy link
Contributor Author

zhaozg commented Oct 1, 2020

after apply LemonBoy@2121716,
run zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -ofmt=pe -lc output is

lld: error: <root>: undefined symbol: _DllMainCRTStartup
error: LLDReportedFailure

@zhaozg
Copy link
Contributor Author

zhaozg commented Oct 11, 2020

Hack 1

zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -ofmt=pe -lc ~/.cache/zig/o/ef7442f9a2b450825bc19e1baa1e2e7f/dllcrt2.o -lmingwex -lmingw32 -lmsvcrt-os
lld: error: <root>: undefined symbol: _DllMainCRTStartup
lld: error: undefined symbol: __DTOR_LIST__
>>> referenced by mingw32.lib(gccmain.o):(__do_global_dtors.p)

lld: error: undefined symbol: __CTOR_LIST__
>>> referenced by mingw32.lib(gccmain.o):(.refptr.__CTOR_LIST__)

lld: error: undefined symbol: __image_base__
>>> referenced by mingw32.lib(pseudo-reloc.o):(.refptr.__image_base__)
>>> referenced by mingw32.lib(pesect.o)
error: LLDReportedFailure

Hack 2

zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -lc -lmingwex -lmingw32 -lmsvcrt-os ~/.cache/zig/o/beb9caf60b28e394e5d788622da3f1b8/dllcrt2.o


lld: error: undefined symbol: __DTOR_LIST__
>>> referenced by mingw32.lib(gccmain.o):(__do_global_dtors.p)

lld: error: undefined symbol: __CTOR_LIST__
>>> referenced by mingw32.lib(gccmain.o):(.refptr.__CTOR_LIST__)

lld: error: undefined symbol: __image_base__
>>> referenced by mingw32.lib(pseudo-reloc.o):(.refptr.__image_base__)
>>> referenced by mingw32.lib(pesect.o)
error: LLDReportedFailure

Hack 3

zig build-lib -target x86_64-windows-gnu -dynamic a_dll.c -lc -lmingwex -lmingw32 -lmsvcrt-os ~/.cache/zig/o/982e2b30a44a3f0138e48dcd2fb8d993/dllcrt2.o
lld: error: undefined symbol: __image_base__
>>> referenced by mingw32.lib(pseudo-reloc.o):(.refptr.__image_base__)
>>> referenced by mingw32.lib(pesect.o)
error: LLDReportedFailure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os-windows zig cc Zig as a drop-in C compiler feature
Projects
None yet
Development

No branches or pull requests

2 participants