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

macos BigSur: ld: library not found for -lSystem #104

Closed
jayvdb opened this issue Jun 14, 2021 · 10 comments · Fixed by #164
Closed

macos BigSur: ld: library not found for -lSystem #104

jayvdb opened this issue Jun 14, 2021 · 10 comments · Fixed by #164

Comments

@jayvdb
Copy link

jayvdb commented Jun 14, 2021

Following the installation instructions, I get the following error.
If I add -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib to the command, it links.

cmake --build build --config Release
   Compiling proc-macro2 v1.0.26
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.71
   Compiling serde_derive v1.0.125
   Compiling serde v1.0.125
   Compiling ryu v1.0.5
   Compiling ucd-trie v0.1.3
   Compiling bitflags v1.2.1
   Compiling camino v1.0.4
   Compiling serde_json v1.0.64
   Compiling platforms v1.1.0
   Compiling unicode-width v0.1.8
   Compiling itoa v0.4.7
   Compiling textwrap v0.11.0
   Compiling pest v2.1.3
   Compiling clap v2.33.3
   Compiling semver-parser v0.10.2
   Compiling quote v1.0.9
   Compiling semver v0.11.0
   Compiling cargo-platform v0.1.1
   Compiling cargo_metadata v0.13.1
   Compiling corrosion-generator v0.1.0 (/Users/john.vandenberg/rust/corrosion/generator)
    Finished release [optimized] target(s) in 23.39s
[  0%] Built target cargo-build_corrosion-generator
[ 12%] Building CXX object test/cpp2rust/CMakeFiles/cpp-lib.dir/lib.cpp.o
[ 25%] Linking CXX static library libcpp-lib.a
[ 25%] Built target cpp-lib
   Compiling corrosion-build v0.1.0 (/Users/john.vandenberg/rust/corrosion/integrator)
   Compiling rust-exe v0.1.0 (/Users/john.vandenberg/rust/corrosion/test/cpp2rust/rust)
error: linking with `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++` failed: exit code: 1
  |
  = note: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" "-m64" "-arch" "x86_64" "-L" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.0.rcgu.o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.1.rcgu.o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.2.rcgu.o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.3.rcgu.o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.4.rcgu.o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.build_script_build.c77xm44p-cgu.5.rcgu.o" "-o" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258" "/Users/john.vandenberg/rust/build/cargo/build/release/build/rust-exe-5a9b6c9d7c91e258/build_script_build-5a9b6c9d7c91e258.1qimn42fvjl4gnum.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/john.vandenberg/rust/build/cargo/build/release/deps" "-L" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/john.vandenberg/rust/build/cargo/build/release/deps/libcorrosion_build-1b83bf0df748c121.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-349f286494d73b18.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-0c9fcc24a503d489.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-70419d92d1ba4b1d.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-65e88774cb68bd46.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-3849b3781a19a398.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-0dbb03fa66ca6d84.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-65edff8661311c85.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-599e707cd7ee7216.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-40cb05f6c516791a.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-7a0a923a4d37a048.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-7e047938e88325ef.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-02542d835be27c0f.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-63712b18a1365082.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-1196a2a060497e71.rlib" "/Users/john.vandenberg/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-10db70d883838cbc.rlib" "-lSystem" "-lresolv" "-lc" "-lm"
  = note: ld: library not found for -lSystem
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: aborting due to previous error
clang -v
Apple clang version 12.0.5 (clang-1205.0.22.9)
Target: x86_64-apple-darwin20.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
@jwintz
Copy link

jwintz commented Sep 5, 2021

Same here. Have you found a relevant and reproducible way to get corrosion add the SDK root to the include directories ?

This bug is especially problematic in the context of cross platform builds, using e.g. iOS toolchains.

@mathstuf
Copy link

Adding --sysroot or something like that should help. But if not, adding ${CMAKE_OSX_SYSROOT}/usr/lib to the link directories should work.

That said, normal CMake libraries don't have this problem normally. Where is -lSystem coming from?

@jschwe
Copy link
Collaborator

jschwe commented Mar 27, 2022

Is this still a problem with CMake >= 3.19?

@jayvdb
Copy link
Author

jayvdb commented Apr 11, 2022

Note I am still seeing this, now on clang 13 and Monterey.

[ 30%] Built target cpp-lib
   Compiling rust-exe v0.1.0 (/Users/jayvdb/rs/corrosion/test/cpp2rust/rust)
error: linking with `/Library/Developer/CommandLineTools/usr/bin/c++` failed: exit status: 1
  |
  = note: "/Library/Developer/CommandLineTools/usr/bin/c++" "-m64" "-arch" "x86_64" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.0.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.1.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.10.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.11.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.12.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.13.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.14.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.15.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.2.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.3.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.4.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.5.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.6.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.7.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.8.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.9.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.3uj3enf3qe83l45c.rcgu.o" "-L" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps" "-L" "/Users/jayvdb/rs/build/cargo/build/release/deps" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-lcpp-lib" "-lcpp-lib2" "-lcpp-lib3" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd-bc98f94cc92dd583.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-4c5913cb1f417199.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libobject-52d68172a078e8e2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-5324831d423fc064.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-0068f19bd8fe5cc2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libgimli-a744d483ff36c65a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-a683a71be634cf78.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-4dd6a2c7baf19e59.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-b2b55b010c3bcb39.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-eb8b1651f40d2e7f.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libunwind-e78454e1999e54e3.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-12e3e23ea6889e4a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liblibc-8a8b9c5cb4feace6.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liballoc-6c3464fa14ab2bc4.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-dc328fc253d5a7e8.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcore-6e6555bfd044460b.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-4c0d76b33e400efb.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057" "-Wl,-dead_strip"
  = note: ld: library not found for -lSystem
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `rust-exe` due to previous error
make[2]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe] Error 1
make[1]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe.dir/all] Error 2
make: *** [all] Error 2
% (cd corrosion && git log --oneline -1)
76bd81d (HEAD -> master, origin/master, origin/HEAD) Fix macos-11 for CMake >= 3.1
% clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

If I run sudo xcode-select -s /Applications/Xcode.app

% clang --version
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: x86_64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Alsmost the same result:

[ 30%] Built target cpp-lib
   Compiling rust-exe v0.1.0 (/Users/jayvdb/rs/corrosion/test/cpp2rust/rust)
error: linking with `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++` failed: exit status: 1
  |
  = note: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" "-m64" "-arch" "x86_64" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.0.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.1.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.10.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.11.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.12.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.13.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.14.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.15.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.2.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.3.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.4.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.5.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.6.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.7.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.8.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.9.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.3uj3enf3qe83l45c.rcgu.o" "-L" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps" "-L" "/Users/jayvdb/rs/build/cargo/build/release/deps" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-lcpp-lib" "-lcpp-lib2" "-lcpp-lib3" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd-bc98f94cc92dd583.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-4c5913cb1f417199.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libobject-52d68172a078e8e2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-5324831d423fc064.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-0068f19bd8fe5cc2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libgimli-a744d483ff36c65a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-a683a71be634cf78.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-4dd6a2c7baf19e59.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-b2b55b010c3bcb39.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-eb8b1651f40d2e7f.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libunwind-e78454e1999e54e3.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-12e3e23ea6889e4a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liblibc-8a8b9c5cb4feace6.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liballoc-6c3464fa14ab2bc4.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-dc328fc253d5a7e8.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcore-6e6555bfd044460b.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-4c0d76b33e400efb.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057" "-Wl,-dead_strip"
  = note: ld: library not found for -lSystem
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `rust-exe` due to previous error
make[2]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe] Error 1
make[1]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe.dir/all] Error 2
make: *** [all] Error 2

If this is a different problem, I am happy to create a new issue.

@jschwe
Copy link
Collaborator

jschwe commented Apr 11, 2022

What cmake version are you using? I only fixed this with the experimental generator, which requires cmake 3.19.
If that is the issue, then I can also add a fix for the old generator.

@jayvdb
Copy link
Author

jayvdb commented Apr 11, 2022

Sorry that was with old version of cmake I have pinned due to day job.

% cmake --version
cmake version 3.21.4

With 3.23.0 I seem similar

[ 30%] Built target cpp-lib2
   Compiling rust-exe v0.1.0 (/Users/jayvdb/rs/corrosion/test/cpp2rust/rust)
error: linking with `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++` failed: exit status: 1
  |
  = note: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++" "-m64" "-arch" "x86_64" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.0.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.1.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.10.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.11.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.12.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.13.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.14.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.15.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.2.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.3.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.4.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.5.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.6.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.7.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.8.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.rust_exe.ac585ba6-cgu.9.rcgu.o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057.3uj3enf3qe83l45c.rcgu.o" "-L" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps" "-L" "/Users/jayvdb/rs/build/cargo/build/release/deps" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/Users/jayvdb/rs/build/test/cpp2rust" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-lcpp-lib" "-lcpp-lib2" "-lcpp-lib3" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd-bc98f94cc92dd583.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-4c5913cb1f417199.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libobject-52d68172a078e8e2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-5324831d423fc064.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-0068f19bd8fe5cc2.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libgimli-a744d483ff36c65a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-a683a71be634cf78.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-4dd6a2c7baf19e59.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-b2b55b010c3bcb39.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-eb8b1651f40d2e7f.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libunwind-e78454e1999e54e3.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-12e3e23ea6889e4a.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liblibc-8a8b9c5cb4feace6.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/liballoc-6c3464fa14ab2bc4.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-dc328fc253d5a7e8.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcore-6e6555bfd044460b.rlib" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-4c0d76b33e400efb.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/usr/local/Cellar/rust/1.58.1/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/jayvdb/rs/build/cargo/build/x86_64-apple-darwin/release/deps/rust_exe-50f67862c7ab0057" "-Wl,-dead_strip"
  = note: ld: library not found for -lSystem
          clang: error: linker command failed with exit code 1 (use -v to see invocation)


error: could not compile `rust-exe` due to previous error
make[2]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe] Error 1
make[1]: *** [test/cpp2rust/CMakeFiles/cargo-build_rust-exe.dir/all] Error 2
make: *** [all] Error 2

I was on rust 1.58.1 ; updating to 1.59.0 - same result.

@jschwe
Copy link
Collaborator

jschwe commented Apr 11, 2022

No the CMake version you were using was recent enough. Maybe my fix only fixed macOS 11, but not 12? Unfortunately macOS 12 does not seem to be availble in github actions, so I can't really test this myself.

Do you know if the location of the System library changed again for macos12 (i.e. is it still at /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib)? Could you do search for /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib in cmake/CorrosionGenerator.cmake and replace the occurences with ${CMAKE_OSX_SYSROOT}/usr/lib and see if that fixes your problem?

@jayvdb
Copy link
Author

jayvdb commented Apr 11, 2022

Using ${CMAKE_OSX_SYSROOT}/usr/lib had no effect.

% ls /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/*System*
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.B.tbd		/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.B_asan.tbd	/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem_asan.tbd

% ls /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/*system*
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libsystemstats.tbd

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/system:
introspection				libdyld.tbd				libsystem_asl.tbd			libsystem_featureflags.tbd		libsystem_pthread.tbd
libcache.tbd				libkeymgr.tbd				libsystem_blocks.tbd			libsystem_info.tbd			libsystem_sandbox.tbd
libcommonCrypto.tbd			libkxld.tbd				libsystem_c.tbd				libsystem_kernel.tbd			libsystem_secinit.tbd
libcompiler_rt.tbd			liblaunch.tbd				libsystem_collections.tbd		libsystem_m.tbd				libsystem_symptoms.tbd
libcopyfile.tbd				libmacho.tbd				libsystem_configuration.tbd		libsystem_malloc.tbd			libsystem_trace.tbd
libcorecrypto.tbd			libmathCommon.A.tbd			libsystem_containermanager.tbd		libsystem_networkextension.tbd		libunc.tbd
libcorecrypto_noasm.tbd			libmathCommon.tbd			libsystem_coreservices.tbd		libsystem_notify.tbd			libunwind.tbd
libcorecrypto_trace.tbd			libquarantine.tbd			libsystem_darwin.tbd			libsystem_platform.tbd			libxpc.tbd
libdispatch.tbd				libremovefile.tbd			libsystem_dnssd.tbd			libsystem_product_info_filter.tbd

gfind / -name 'libSystem*' shows some powershell and dotnet files, and nothing else except for those mentioned above in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/

@jschwe jschwe reopened this Apr 11, 2022
@jschwe
Copy link
Collaborator

jschwe commented Apr 12, 2022

I investigated this, and I think I should have a fix, but I'll leave my findings here for documentation purposes in case someone has a similar problem in the future:

For Rust targets, Rust will invoke the linker and add (among others) the -lSystem flag. This works fine for the default linker, but if we use a custom linker (e.g. g++, or even /usr/bin/ld), then we must provide that path to the System library.

  • Adding -L<path> to RUSTFLAGS works fine for regular libraries, but fails for build-scripts (See There is no way to set RUSTFLAGS for build scripts when cross-compiling rust-lang/cargo#4423). This is mostly an issue because we always specify the target, even when building for host, but that is already sufficient for the RUSTFLAGS to not apply to the build-script-build.
  • target specific RUSTFLAGS (i.e CARGO_TARGET_<triple>_RUSTFLAGS also don't seem to affect buildscripts.
  • Setting LIBRARY_PATH=<path> applies to normal targets and build-scripts too, and seems to fix the issue.
  • My previous fix probably only fixed the case where a rust library gets linked into a foreign library or executable.

@jayvdb Could you checkout #167 and check if this PR also fixes the problem on macos-12?

@jayvdb
Copy link
Author

jayvdb commented Apr 12, 2022

That PR wfm on macos 12.3.1 / clang 13.1.6 / CommandLineTools 13.3

@jschwe jschwe closed this as completed Apr 12, 2022
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

Successfully merging a pull request may close this issue.

4 participants