cxx icon indicating copy to clipboard operation
cxx copied to clipboard

Add reference to rustflags for linking configuration

Open mattiekat opened this issue 4 years ago • 1 comments

Spent about 2 days trying to debug an issue with linking to OpenGL which is being called from C++ code connected via cxx and a couple other system libraries. This issues turned out to be because the cargo:rustc-link-lib was putting the link too early in the linking command and needed to be at the end of the cc call.

This was not an issue on Windows because (as far as I can tell anyway) msvc does not care about the ordering as much, but is on Linux.

While this is a very niche issue for rust as a whole, I am sure it is significantly more common among users of cxx. From what I can tell, this is an issue with cases where your C/C++ code connected via cxx needs to link to system libraries.

This is not a bug with cxx, however, I think it would be helpful if a reference to rustflags (specifically with -C link-arg= for linking) in the docs, and also a reference to the nightly cargo feature extra-link-arg which allows for adding these in the build.rs script.

mattiekat avatar Jun 13 '21 19:06 mattiekat

This definitely needs to be added, I spent 3 days figuring out why an external lib that my C++ code needed wouldn't link, before running into extra-link-arg

t348575 avatar Jun 10 '22 08:06 t348575