MacOS 上的 CMAKE 交叉编译将 MacOS SDK 添加到 flags.make 中的 -isysroot
CMAKE cross compile on MacOS adds MacOS SDK to -isysroot in flags.make
Cmake 是广告
我正在尝试使用 cmake 在 Mac 上交叉编译 raspberry pi 3+ 以生成 makefile。我的 CMakeLists.txt:
cmake_minimum_required (VERSION 3.11.0)
project(decatrack)
# setup cross toolchain for RPi 3
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(TOOLCHAIN_DIR /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf)
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-g++)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
unset(CMAKE_OSX_DEPLOYMENT_TARGET
# c++ standerd
# force cc++03 standard
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++11")
include_directories(
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/usr/include
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include
)
target_link_libraries (
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/lib/libpigpio.so
)
add_subdirectory(src)
生成的 flags.make 文件如下所示(您必须滚动才能看到问题:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.11
# compile CXX with /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/bin/armv8-rpi3-linux-gnueabihf-g++
CXX_FLAGS = -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -std=gnu++11
CXX_DEFINES =
CXX_INCLUDES = -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0 -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include
它添加了“-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk”,我不知道如何阻止它!!!
我发现了一个 post 建议将 CMAKE_OSX_SYSROOT 设置为您的交叉编译项目的 sysroot,它成功了!我补充说:
set(CMAKE_OSX_SYSROOT /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/sysroot)
一切都很好。
我在 PlatformIO 的帮助下在 MacOS 上使用 CLion 进行开发时遇到了一个非常相似的问题,我得到:
unrecognized command line option '-mmacosx-version-min=xx.xx
这个问题(以及上面那个)的解决方案是设置 -nostdlib
像这样:
SET(CMAKE_C_COMPILER "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc")
SET(CMAKE_CXX_COMPILER "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-g++")
SET(CMAKE_CXX_FLAGS "-nostdlib")
SET(CMAKE_C_FLAGS "-nostdlib")
# optional
SET(CMAKE_OSX_SYSROOT "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/sysroot")
重要!在 project(...)
之前添加这些行
Cmake 是广告 我正在尝试使用 cmake 在 Mac 上交叉编译 raspberry pi 3+ 以生成 makefile。我的 CMakeLists.txt:
cmake_minimum_required (VERSION 3.11.0)
project(decatrack)
# setup cross toolchain for RPi 3
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(TOOLCHAIN_DIR /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf)
set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/armv8-rpi3-linux-gnueabihf-g++)
set(CMAKE_SYSROOT ${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
unset(CMAKE_OSX_DEPLOYMENT_TARGET
# c++ standerd
# force cc++03 standard
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Using C++11")
include_directories(
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/usr/include
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include
${TOOLCHAIN_DIR}/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/include
)
target_link_libraries (
${TOOLCHAIN_DIR}/armv8-rpi3-linux-gnueabihf/sysroot/lib/libpigpio.so
)
add_subdirectory(src)
生成的 flags.make 文件如下所示(您必须滚动才能看到问题:
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.11
# compile CXX with /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/bin/armv8-rpi3-linux-gnueabihf-g++
CXX_FLAGS = -std=c++11 -mcpu=cortex-a53 -mfloat-abi=hard -mfpu=neon-fp-armv8 -mneon-for-64bits -ggdb -O0 -ffunction-sections -fdata-sections -v -shared-libgcc -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -std=gnu++11
CXX_DEFINES =
CXX_INCLUDES = -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0 -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include/c++/6.3.0/backward -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/lib/gcc/armv8-rpi3-linux-gnueabihf/6.3.0/include-fixed -I/Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/include
它添加了“-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk”,我不知道如何阻止它!!!
我发现了一个 post 建议将 CMAKE_OSX_SYSROOT 设置为您的交叉编译项目的 sysroot,它成功了!我补充说:
set(CMAKE_OSX_SYSROOT /Volumes/xtool-build-env/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/sysroot)
一切都很好。
我在 PlatformIO 的帮助下在 MacOS 上使用 CLion 进行开发时遇到了一个非常相似的问题,我得到:
unrecognized command line option '-mmacosx-version-min=xx.xx
这个问题(以及上面那个)的解决方案是设置 -nostdlib
像这样:
SET(CMAKE_C_COMPILER "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-gcc")
SET(CMAKE_CXX_COMPILER "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-g++")
SET(CMAKE_CXX_FLAGS "-nostdlib")
SET(CMAKE_C_FLAGS "-nostdlib")
# optional
SET(CMAKE_OSX_SYSROOT "$ENV{HOME}/.platformio/packages/toolchain-xtensa32/xtensa-esp32-elf/sysroot")
重要!在 project(...)