【问题标题】:How to compile from windows to raspberry pi 4 using cmake+clang?如何使用 cmake+clang 从 windows 编译到树莓派 4?
【发布时间】:2021-05-05 11:09:14
【问题描述】:

我试图用clang将简单的helloworld从Windows机器编译到树莓派机器。但它给了我错误。

从 llvm.org 下载的 Clang。安装到 C:/Program Files/LLVM。

CMakeLists.txt 文件

cmake_minimum_required(VERSION 3.8.0)
project(test)

add_executable(${PROJECT_NAME} 
    main.cpp
)

clang_arm.cmake 文件

cmake_minimum_required(VERSION 3.10)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR ARM)

set(CLANG_TARGET_TRIPLE arm-none-eabi)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_ASM_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_CXX_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})
set(CMAKE_ASM_COMPILER_TARGET ${CLANG_TARGET_TRIPLE})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

ma​​in.cpp 文件

#include <iostream>

int main()
{
    std::cout << "hello world" << std::endl;
    system("pause");
    return 0;
}

build.cmd 文件

mkdir build
cd build
cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=clang_arm.cmake
ninja

当我尝试执行 build.cmd 文件时,它输出错误:

C:\dev\test>mkdir build

C:\dev\test>cd build

C:\dev\test\build>cmake .. -G Ninja -DCMAKE_TOOLCHAIN_FILE=clang_arm.cmake
-- The C compiler identification is Clang 11.0.0
-- The CXX compiler identification is Clang 11.0.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.19/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "C:/Program Files/LLVM/bin/clang.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/dev/test/build/CMakeFiles/CMakeTmp

    Run Build Command(s):C:/PROGRA~1/Ninja/ninja.exe cmTC_0203b && [1/2] Building C object CMakeFiles/cmTC_0203b.dir/testCCompiler.c.obj
    [2/2] Linking C executable cmTC_0203b
    FAILED: cmTC_0203b
    cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\clang.exe --target=arm-none-eabi   CMakeFiles/cmTC_0203b.dir/testCCompiler.c.obj -o cmTC_0203b   && cd ."
    ld.lld: error: unable to find library -lc
    ld.lld: error: unable to find library -lm
    ld.lld: error: unable to find library -lclang_rt.builtins-arm
    clang: error: ld.lld command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.





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


-- Configuring incomplete, errors occurred!
See also "C:/dev/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/dev/test/build/CMakeFiles/CMakeError.log".

C:\dev\test\build>ninja
ninja: error: loading 'build.ninja': ═х єфрхЄё  эрщЄш єърчрээ√щ Їрщы.

【问题讨论】:

    标签: c++ windows cmake clang


    【解决方案1】:

    正如链接器的输出所提到的

    ld.lld: error: unable to find library -lc
    ld.lld: error: unable to find library -lm
    ld.lld: error: unable to find library -lclang_rt.builtins-arm
    

    找不到 libm、libc 和 libclang_rt.buildins-arm。您必须使用 -L 提供库路径。您还可以告诉 CMAKE 在您的文件 clang_arm.cmake 中使用 CMAKE_SYSROOT 的系统库默认应该在哪里查找

    set(CMAKE_SYSROOT /your/path/with/std_libraries)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-24
      • 2021-10-12
      • 2021-05-17
      • 2021-03-01
      • 1970-01-01
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多