Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upC runtime library is not linked on macOS #59164
Comments
sanxiyn
added
A-linkage
O-macos
labels
Mar 22, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
lwshang commentedMar 13, 2019
•
edited
Problem
rustc is not default to link C runtime library on macOS. I'm trying to write rust binding for a C library. That C library is shipped with my crate by a git submodule. The C library uses functionality provide by C runtime library. When I run
cargo testwithout any special cargo configuration, it failed at linking stage because it cannot find the symbol__emutls_get_addresswhich is provided in C runtime library.The bug doesn't happen on Linux. On Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-46-generic x86_64). With the help of nightly
rustc -Z print-link-args, I found out that rustc on linux has a link arg-lgcc_swhich resolve to/usr/lib/gcc/x86_64-linux-gnu/7/libgcc_s.so.Steps
.cargo/configPossible Solution(s)
Currently, I have a workaround to separately add link-args in
.cargo/configwhich specify the path to a C runtime library. But this is just a temporary solution, since the path is version sensitive, it will be different on different version of macOS with different version of Xcode.If we compile a C program, the final link process always links a C runtime library. Depends on the compiler, different lib will be linked.
If using macOS 10.14.3 system clang, it links
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a. (This is what I have in.cargo/config)If using brew gcc-8, there is a link arg
-lgcc_ext.10.5which resolve to/usr/local/Cellar/gcc/8.3.0/lib/gcc/8/libgcc_ext.10.5.dylib.If rustc default to link the first one (
libclang_rt.osx.a), the special setting in.cargo/configwill be non-necessary.meta