簡體   English   中英

如何使用 cmake+clang 從 windows 編譯到樹莓派 4?

[英]How to compile from windows to raspberry pi 4 using cmake+clang?

我試圖用 clang 將簡單的 helloworld 從 windows 機器編譯到樹莓派機器。 但它給了我錯誤。

Clang 從 llvm.org 下載。 安裝到 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)

main.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 文件時,出現 output 錯誤:

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': ═х єфрхЄё  эрщЄш єърчрээ√щ Їрщы.

正如 linker 的 output 所述

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM