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

LLVM测试篇-交叉编译:clang-13: error: linker command failed with exit code 1 (use -v to see invocation) #1

Closed
xijing21 opened this issue Jun 4, 2021 · 4 comments

Comments

@xijing21
Copy link

xijing21 commented Jun 4, 2021

按照https://github.com/mollybuild/RISCV-Measurement/blob/master/Build-RISCV-LLVM-and-run-testsuite.md 执行交叉编译的时候,cmake报错:

xj@e2ba8bd04169:~/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build$ cmake -DCMAKE_TOOLCHAIN_FILE=/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/clang_riscv_linux.cmake  -DCMAKE_C_COMPILER="/home/xj/RISCV/llvm-project0/build/bin/clang"  ../test-suite
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Check for working C compiler: /home/xj/RISCV/llvm-project0/build/bin/clang
-- Check for working C compiler: /home/xj/RISCV/llvm-project0/build/bin/clang -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/home/xj/RISCV/llvm-project0/build/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make cmTC_c5958/fast && /usr/bin/make -f CMakeFiles/cmTC_c5958.dir/build.make CMakeFiles/cmTC_c5958.dir/build
    make[1]: Entering directory '/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o
    /home/xj/RISCV/llvm-project0/build/bin/clang --target=riscv64-unknown-linux-gnu --gcc-toolchain=/home/xj/RISCV/linux/    -o CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o   -c /home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_c5958
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c5958.dir/link.txt --verbose=1
    /home/xj/RISCV/llvm-project0/build/bin/clang --target=riscv64-unknown-linux-gnu --gcc-toolchain=/home/xj/RISCV/linux/    -static  CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o  -o cmTC_c5958
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: warning: -z relro ignored
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: unrecognized option '--hash-style=gnu'
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: use the --help option for usage information
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_c5958.dir/build.make:87: cmTC_c5958] Error 1
    make[1]: Leaving directory '/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_c5958/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!
See also "/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeOutput.log".
See also "/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeError.log".

@xijing21
Copy link
Author

xijing21 commented Jun 4, 2021

image

@xijing21
Copy link
Author

xijing21 commented Jun 4, 2021

image
image
image

@mollybuild
Copy link
Owner

按照https://github.com/mollybuild/RISCV-Measurement/blob/master/Build-RISCV-LLVM-and-run-testsuite.md 执行交叉编译的时候,cmake报错:

xj@e2ba8bd04169:~/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build$ cmake -DCMAKE_TOOLCHAIN_FILE=/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/clang_riscv_linux.cmake  -DCMAKE_C_COMPILER="/home/xj/RISCV/llvm-project0/build/bin/clang"  ../test-suite
-- The C compiler identification is Clang 13.0.0
-- The CXX compiler identification is Clang 13.0.0
-- Check for working C compiler: /home/xj/RISCV/llvm-project0/build/bin/clang
-- Check for working C compiler: /home/xj/RISCV/llvm-project0/build/bin/clang -- broken
CMake Error at /usr/share/cmake-3.16/Modules/CMakeTestCCompiler.cmake:60 (message):
  The C compiler

    "/home/xj/RISCV/llvm-project0/build/bin/clang"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp

    Run Build Command(s):/usr/bin/make cmTC_c5958/fast && /usr/bin/make -f CMakeFiles/cmTC_c5958.dir/build.make CMakeFiles/cmTC_c5958.dir/build
    make[1]: Entering directory '/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o
    /home/xj/RISCV/llvm-project0/build/bin/clang --target=riscv64-unknown-linux-gnu --gcc-toolchain=/home/xj/RISCV/linux/    -o CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o   -c /home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_c5958
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_c5958.dir/link.txt --verbose=1
    /home/xj/RISCV/llvm-project0/build/bin/clang --target=riscv64-unknown-linux-gnu --gcc-toolchain=/home/xj/RISCV/linux/    -static  CMakeFiles/cmTC_c5958.dir/testCCompiler.c.o  -o cmTC_c5958
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: warning: -z relro ignored
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: unrecognized option '--hash-style=gnu'
    /home/xj/RISCV/linux/lib/gcc/riscv64-unknown-elf/10.2.0/../../../../riscv64-unknown-elf/bin/ld: use the --help option for usage information
    clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
    make[1]: *** [CMakeFiles/cmTC_c5958.dir/build.make:87: cmTC_c5958] Error 1
    make[1]: Leaving directory '/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_c5958/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:7 (project)


-- Configuring incomplete, errors occurred!
See also "/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeOutput.log".
See also "/home/xj/RISCV/llvm-project0/llvm/projects/test-suite-riscv-build/CMakeFiles/CMakeError.log".

指定的target是riscv64-unknown-linux-gnu, ld用的是riscv64-unknown-elf,不一致。

@xijing21
Copy link
Author

xijing21 commented Jun 4, 2021

重新构建riscv-gnu-toolchain的linux函数库:

build$ mkdir linux
build$ cd linux
linux$ ../../configure --prefix=$RISCV/linux
linux$ make linux   # 注意这里是make linux

make完之后:
image

cmake还是报错:
image
/home/xj/RISCV/linux/lib/gcc/riscv64-unknown-linux-gnu/10.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory

解决办法:修改环境变量,在~/.bashrc中的path中添加linux构建目录:~/RISCV/linux/bin 再次cmake就好了

@xijing21 xijing21 closed this as completed Jun 4, 2021
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

2 participants