mystor / rust-cpp

Embed C++ directly inside your rust code!
Apache License 2.0
802 stars 44 forks source link

put "-l" "rust_cpp_generated" before other libraries #26

Closed fneddy closed 7 years ago

fneddy commented 7 years ago

if I do this in build.rs:main

   let mut conf = cpp_build::Config::new();
   conf.flag("-lSomeLib");
   conf.build("src/main.rs");

sometimes the linker gets an error of the kind undefined reference.

error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" ...
  ..."-l" "SomeLib" ... "-l" "rust_cpp_generated"
  = note: /home/fneddy/Projects/qpp/target/debug/build/qpp-f6ef9f4261aba55c/out/librust_cpp_generated.a(cpp_closures.o): In function `__cpp_closure_12982553034344175645':
  /home/fneddy/Projects/qpp/src/main.rs:18: undefined reference to `SomeLib::SomeLib()' 
   ...

if i then copy the complete cc command and put the "-l" "rust_cpp_generated" before the "-l" "SomeLib" there is no error.

is there a way to force the order of the linker instructions?

fneddy commented 7 years ago

the important line might be in gcc-rs and not in cpp-rs:

https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L734

fneddy commented 7 years ago

ahhh never mind ... this is not an issue

this issue because using the pkg_config crate to find the libraries. But pkg_config::Config::probe_library will automatically print the rustc metadat.

this issue is solved