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

error: linking with cc failed: exit status: 1 #1006

Open
chenlvzhou opened this issue Mar 12, 2024 · 2 comments
Open

error: linking with cc failed: exit status: 1 #1006

chenlvzhou opened this issue Mar 12, 2024 · 2 comments

Comments

@chenlvzhou
Copy link

chenlvzhou commented Mar 12, 2024

 cc::Build::new()
        .cpp(true)
        .warnings(true)
        .flag("-Wall")
        .flag("-std=c++14")
        .flag("-c")
        .files(["cpp_src/sorting.cpp", "cpp_src/print.cpp"])
        .compile("sorting");                 
        error: linking with `cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET LC_ALL="C" PATH="/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/bin:/Users/mac/.cargo/bin:/Users/mac/software/anaconda3/condabin:/Users/mac/software/apache-maven/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/go/bin" VSLANG="1033" ZERO_AR_DATE="1" "cc" "-arch" "x86_64" "-m64" "/var/folders/1l/2z44fqw54rb2fztm8nk_0t2w0000gn/T/rustck33v2F/symbols.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.1pxhp3o9rtxxrxmg.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.1tg1n1hwo6j88wgy.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.2d3iqpbqldef27iz.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.2dkclog6uyd8qahj.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.3abpx8lt5d9ohof3.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.445p9yoszwkg5914.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.4nsqznq8pageah3j.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.4q8e8cefm8ipxqik.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.56j97f27rkka71kq.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.s1p2zarxq8bsnav.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.yzs1ijr2apqy1rs.rcgu.o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf.403mriweq4m37mka.rcgu.o" "-L" "/Users/mac/study/rustdemo/target/debug/deps" "-L" "/Users/mac/study/rustdemo/target/debug/build/rustdemo-9515264eef5f7eaa/out" "-L" "/Users/mac/study/rustdemo/target/debug/build/rustdemo-9515264eef5f7eaa/out" "-L" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-lhello" "-lsorting" "-lc++" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-4b3c9502f998a9c9.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-53709cde6aa4a693.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-1494d77bb023321a.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-68a50e7561e64f6e.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-111bf54042d9c9b3.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-2fc45f03240cf281.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-aa7833ff327b252f.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-d99d527ee281d1c7.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-cc55eed8d39cd8fc.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-c6547d77ecacc8da.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libminiz_oxide-9959121601c10901.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libadler-a6adcc42a6c760f5.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-133909f66e1d85ed.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-e3e353dbd0bf39e3.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-f33d75ee38b367b8.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-968bc4f3f78458d4.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-f8bf7097e7997f38.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-4406d769bde4f34a.rlib" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-1ebaaaec5ccf50e8.rlib" "-lSystem" "-lc" "-lm" "-L" "/Users/mac/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/mac/study/rustdemo/target/debug/deps/rustdemo-743f6d5e588be2bf" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: Undefined symbols:
            _print_message, referenced from:
                rustdemo::print_message_cpp::h0a6a34a8e6eaa652 in rustdemo-743f6d5e588be2bf.s1p2zarxq8bsnav.rcgu.o
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
          

error: aborting due to 1 previous error; 1 warning emitted

Merge multiple cpp files and compile them into one .a file

@NobodyXu
Copy link
Collaborator

= note: ld: Undefined symbols:
_print_message, referenced from:
rustdemo::print_message_cpp::h0a6a34a8e6eaa652 in rustdemo-743f6d5e588be2bf.s1p2zarxq8bsnav.rcgu.o

It seems that there's an undefined symbols in your crate rustdemo

@workingjubilee
Copy link

@chenlvzhou Please provide enough code to reproduce your error, otherwise we will not be able to determine how to fix this.

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