fubark / cyber

Fast and concurrent scripting.
https://cyberscript.dev
MIT License
1.16k stars 38 forks source link

Embeddable static library undefined symbols #81

Closed ccleavinger closed 6 months ago

ccleavinger commented 6 months ago

I've been working an a small C++ wrapper over cyber for game engine development. I've fixed almost all the issues other than these errors from within the *.lib: 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol NtCreateFile referenced in function os.windows.OpenFile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol __fixunsdfti referenced in function fmt.errol.errol3 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol __udivti3 referenced in function fmt.errol.errol3 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol __umodti3 referenced in function fmt.errol.errol3 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol ___chkstk_ms referenced in function vm_compiler.VMcompiler.compile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol RtlGetFullPathName_U referenced in function vm_compiler.VMcompiler.compile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol NtQueryObject referenced in function vm_compiler.VMcompiler.compile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol NtDeviceIoControlFile referenced in function vm_compiler.VMcompiler.compile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol NtClose referenced in function vm_compiler.VMcompiler.compile 1>libcyber-windows-x64.lib(cyber.lib.obj) : error LNK2019: unresolved external symbol RtlWaitOnAddress referenced in function heap.CAllocator.free

It looks like issues from within the zig std library and a few function calls that it has no idea about. I've spent ~a week trying to trouble shoot this and am curious if you have any insights.

fubark commented 6 months ago

Are you linking with the lib from releases? I'm not on a windows machine but this looks like it's relevant: https://www.github.com/ziglang/zig/issues/2771

In build.zig you can set lib.bundle_compiler_rt = true;

ccleavinger commented 6 months ago

I was using the lib from releases. I'll try using -ffunction-sections with "version": "0.12.0-dev.1817+f88b52306"

ccleavinger commented 6 months ago

This probably sounds like a really dumb question but what was the command that you used to build for a windows static library? (Zig is not my forte)

fubark commented 6 months ago

I did a cross compile on my M2 using zig build lib -Dtarget=x86_64-windows-gnu and was able to link with a C++ version of c-embedded/main.c using zig c++ main.cpp -I ../../src/include ../../zig-out/lib/cyber.lib -o main.

Make sure you're using Zig 0.11.0 release. zigup is a nice tool to download and manage zig versions. Also you might try targeting MSVC.

ccleavinger commented 6 months ago

Still have the issue and am no closer to solving it. I'll close this issue and I'll open another issue in the zig repository regarding issues with MSVC linking. Thanks for all your help!

fubark commented 6 months ago

Btw, regarding the other symbols. You could try adding lib.linkLibCpp(); in the build.zig file too and also including the system libraries that they belong to like lib.linkSystemLibrary("ntdll"). One my windows machine gets fixed I should be able to check if I can reproduce.