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

Linking against a DLL file #271

Closed
orthecreedence opened this issue Nov 9, 2017 · 6 comments
Closed

Linking against a DLL file #271

orthecreedence opened this issue Nov 9, 2017 · 6 comments

Comments

@orthecreedence
Copy link

Hello. Thanks for this project! So far it seems really cool. I have a weird dilemma I'm hoping you can help out with.

I have a somewhat largish rust app (called Turtl) I'm building with the rust windows GNU toolchain. It needs to compile against gnu (I'm on msys2/mingw64) because some of the dependencies won't compile on msvc. Since Neon requires the msvc toolchain (as far as I can tell), I unfortunately can't directly load my crate into the neon plugin under the [dependencies]. I've decided instead to compile my project to a library (.dll/.lib) that exposes a C api and call out to it from generated bindings.

I have two problems at this point.

  1. When Neon links against my library file, it seems to only look for the static lib (turtl_core.lib). Ok, fine, I compile turtl as a static library, which Neon finds when compiling, but I get this error:

    error: linking with `link.exe` failed: exit code: 1120
      |
      = note: "C:\\dev\\Microsoft Visual Studio\\2017\\BuildTools\\VC\\Tools\\MSVC\\14.10.25017\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\turtl_phone.0.o" "/OUT:C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\turtl_phone.dll" "/DEF:C:\\msys2\\tmp\\rustc.7DGZPclcw58G\\lib.def" "C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\turtl_phone.crate.allocator.o" "/OPT:REF,ICF" "/DEBUG" "/NATVIS:C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/LIBPATH:C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps" "/LIBPATH:C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\release\\deps" "/LIBPATH:c:\\\\include" "/LIBPATH:c:\\\\lib" "/LIBPATH:c:\\\\htdocs\\\\turtl\\\\desktop\\\\.build" "/LIBPATH:C:\\\\Users\\\\andrew\\\\.node-gyp\\\\8.9.0\\Release" "/LIBPATH:C:\\\\Users\\\\andrew\\\\.node-gyp\\\\8.9.0\\x64" "/LIBPATH:C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\build\\neon-runtime-793f95d90703337b\\out" "/LIBPATH:C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "node.lib" "turtl_core.lib" "C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\libneon-371bf33ee7aba21c.rlib" "C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\libneon_runtime-380f368fffbdef8c.rlib" "C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\libcslice-341b156c0321b8bd.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-21987e9ade021f69.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-29d6158f38a84c5f.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-d6c8212ee950c463.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-09b6e1422795dd7b.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-2db463290136f98d.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-9d760f50c87565b2.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_unicode-814c9462c44e78d7.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-164988f0cb62f1a9.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-3ca6fddda4df5c3d.rlib" "C:\\Users\\andrew\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-3d1abc484b0c6c31.rlib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "msvcrt.lib" "/DLL" "/IMPLIB:C:\\htdocs\\turtl\\desktop\\turtl_phone\\native\\target\\x86_64-pc-windows-msvc\\release\\deps\\turtl_phone.dll.lib"
      = note:    Creating library C:\htdocs\turtl\desktop\turtl_phone\native\target\x86_64-pc-windows-msvc\release\deps\turtl_phone.dll.lib and object C:\htdocs\turtl\desktop\turtl_phone\native\target\x86_64-pc-windows-msvc\release\deps\turtl_phone.dll.exp
              turtl_core.lib(posix.o) : error LNK2019: unresolved external symbol open referenced in function backtrace_open
              turtl_core.lib(posix.o) : error LNK2019: unresolved external symbol close referenced in function backtrace_close
              turtl_core.lib(read.o) : error LNK2019: unresolved external symbol lseek referenced in function backtrace_get_view
              turtl_core.lib(read.o) : error LNK2019: unresolved external symbol read referenced in function backtrace_get_view
              turtl_core.lib(dwarf.o) : error LNK2019: unresolved external symbol __ms_vsnprintf referenced in function snprintf.constprop.13
              C:\htdocs\turtl\desktop\turtl_phone\native\target\x86_64-pc-windows-msvc\release\deps\turtl_phone.dll : fatal error LNK1120: 5 unresolved externals
    

    I've been looking everywhere online and haven't found a solution, and no matter what combination of -l<lib> I use in RUSTFLAGS I still get these errors.

  2. So now, I'm thinking maybe it would be more effective to compile turtl to a .dll instead, but I'm having trouble telling Neon to look for a DLL instead of a LIB. I tried a number of different combinations of things in build.rs in the neon project, but no luck.

I'm wondering three things:

  1. Can I just use the gnu toolchain to compile the neon project? I'm guessing it uses node-gyp somewhere along the way, so probably not since it doesn't support mingw, but thought I'd check anyway =].
  2. Any idea on what those link errors are from when using the static lib? I understand if not, it's not really in the scope of the project but worth asking anyway.
  3. Can I point neon at a .dll file when compiling instead of a .lib?

Thanks so much for your help!

@bnoordhuis
Copy link

Can I just use the gnu toolchain to compile the neon project?

Nope, for the reason you mention. It goes further than node-gyp: node.exe is compiled with cl.exe and cl.exe does name mangling differently than mingw. clang-cl might work, though.

Any idea on what those link errors are from when using the static lib?

The first four look like you linked in code intended for POSIX platforms (i.e., non-Windows.)

The __ms_vsnprintf thing looks like a mingw issue, see e.g. https://sourceforge.net/p/libusb/mailman/message/34300859/

Can I point neon at a .dll file when compiling instead of a .lib?

No, although you could perhaps load the DLL and look up symbols dynamically. Rather less convenient though.

@orthecreedence
Copy link
Author

Thanks, your answers help a lot (and make it clear which direction I need to go in).

Do you know of a way to tell rustc to pass -D__USE_MINGW_ANSI_STDIO to gcc when building? I've tried setting CFLAGS directly but I don't think it "takes."

@bnoordhuis
Copy link

No idea, sorry.

@nixpulvis
Copy link

nixpulvis commented Nov 9, 2017

You might find something useful in this thread. Sorry if I've misunderstood your use case, since it does say "linker arguments". rust-lang/rfcs#1766

@nixpulvis
Copy link

nixpulvis commented Nov 9, 2017

This might also be worth looking at since it looks like it lets you set CFLAGS directly. https://github.com/alexcrichton/cc-rs

@orthecreedence
Copy link
Author

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants