- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我喜欢在 Windows 构建服务器上自动执行多个项目的交叉编译。我在使用 arm 交叉编译器时遇到了一些问题。设置它似乎有点困难。 cmake 编译器检查因链接错误而失败(见下文)。
我的实验项目是这样的:
main.cpp - a test programm
CMakeLists.txt - the cmake build script
cmake/STM32F2xx.cmake - the special settings for the ARM STM32F2xx-series
我正在使用 3 个包:
cmake-3.8.0-win64-x64.msi -cmake for windows
mingw-w64-install.exe - mingw 64 for windows
gcc-arm-none-eabi-6-2017-q1-update-win32.exe - arm x compiler
main.cpp 包含:
int main(void) {
return 0;
}
CMakeLists.txt 包含:
cmake_minimum_required (VERSION 3.0)
# module name
set(PrjName testPrj)
project (${PrjName})
# module version
set(PCK_MAJOR 1)
set(PCK_MINOR 0)
set(PCK_REVISION 0)
#####################
# Features switches
#####################
#####################
# architecture
#####################
# possible values:
# NATIVE
# STM32F2xx
SET(Arch NATIVE CACHE STRING "Architecture")
#############################
# software stack search path
############################
SET(SWstackPath NONE CACHE STRING "software stack search path")
#############################
# software stack handling
############################
if (${SWstackPath} STREQUAL NONE)
else ()
include_directories(${SWstackPath})
endif()
#############################
# package creation
#############################
SET(PackageFormat "DEFAULT" CACHE STRING "the format of the installation package")
########################
# define module content
########################
# MetaData header
set(testApp "testApp")
set(${testApp}_VERSION_MAJOR 1)
set(${testApp}_VERSION_MINOR 2)
set(${testApp}_VERSION_REVISION 3)
set(${testApp}_SOVERSION 4)
########################
# architecture handling
########################
if(${Arch} STREQUAL NATIVE)
MESSAGE("Architecture is set to NATIVE")
else()
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/${Arch}.cmake)
endif()
if (${PackageFormat} STREQUAL "DEFAULT")
if (UNIX)
include(GNUInstallDirs)
set(CPACK_GENERATOR "DEB")
else ()
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_FULL_BINDIR "bin")
set(CMAKE_INSTALL_FULL_LIBDIR "lib")
set(CMAKE_INSTALL_FULL_LIBDIRSTATIC "lib")
set(CMAKE_INSTALL_FULL_INCLUDEDIR "include")
set(CMAKE_INSTALL_FULL_MANDIR "doc")
endif()
elseif(${PackageFormat} STREQUAL "ZIP")
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_FULL_BINDIR "bin")
set(CMAKE_INSTALL_FULL_LIBDIR "lib")
set(CMAKE_INSTALL_FULL_LIBDIRSTATIC "lib")
set(CMAKE_INSTALL_FULL_INCLUDEDIR "include")
set(CMAKE_INSTALL_FULL_MANDIR "doc")
else()
message( FATAL_ERROR "The PackageFormat is unknown")
endif()
################################
# compile of the module content
################################
list(APPEND testApp_sources
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
add_executable(${testApp}
${testApp_sources}
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set_target_properties(${testApp} PROPERTIES
LINKER_LANGUAGE CXX
)
################################
# installation
################################
if(EXISTS "${CMAKE_ROOT}/Modules/CPack.cmake")
# install app
install(
TARGETS ${testApp}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}/static
)
set(CPACK_PACKAGE_DESCRIPTION "test")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "test")
set(CPACK_PACKAGE_VENDOR "xxx")
set(CPACK_PACKAGE_CONTACT "xxx")
set(CPACK_PACKAGE_VERSION_MAJOR "${PCK_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PCK_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PCK_REVISION}")
set(CPACK_PACKAGE_FILE_NAME "${PrjName}_${PCK_MAJOR}.${PCK_MINOR}.${PCK_REVISION}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PrjName}_${PCK_MAJOR}.${PCK_MINOR}.${PCK_REVISION}")
include(CPack)
endif()
cmake/STM32F2xx.cmake 包含:
set(CMAKE_C_FLAGS_INIT "--cpu Cortex-M3")
set(CMAKE_CXX_FLAGS_INIT "--cpu Cortex-M3")
set(CMAKE_C_LINK_FLAGS_INIT "--zt")
我为 arm 编译器创建了一个工具链文件:
# generated cmake toolchain file for
include (CMakeForceCompiler)
# We are cross compiling so we don't want compiler tests to run, as they will fail
set(CMAKE_SYSTEM_NAME Generic)
# Set processor type
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)
set(CMAKE_ASM_COMPILER "arm-none-eabi-as.exe")
set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")
set(CMAKE_LINKER "arm-none-eabi-gcc.exe")
set(CMAKE_MAKE_PROGRAM "mingw32-make.exe")
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)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --specs=nosys.specs")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --specs=nosys.specs")
在 cmd 上编译时:
cd D:\git\myTestBuild\build
PATH=C:\Program Files\CMake\bin;C:\Program Files (x86)\GNU Tools ARM Embedded\6 2017-q1-update\bin;C:\Program Files\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev2\mingw64\bin;%PATH%
"C:\Program Files\CMake\bin\cmake.exe" -DArch="STM32F2xx" -G"MinGW Makefiles" -DPackageFormat=ZIP -DSWstackPath="D:\git\myTestBuild\SWstack" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="D:\git\myTestBuild\dump\toolchain.cmake" ..
CMake Error at C:/Program Files/CMake/share/cmake-3.8/Modules/CMakeTestCCompiler.cmake:51 (message):
The C compiler "C:/Program Files (x86)/GNU Tools ARM Embedded/6
2017-q1-update/bin/arm-none-eabi-gcc.exe" is not able to compile a simple
test program.
It fails with the following output:
Change Dir: D:/git/myTestBuild/build/CMakeFiles/CMakeTmp
Run Build Command:"C:/Program
Files/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/bin/mingw32-make.exe"
"cmTC_8c052/fast"
C:/Program
Files/mingw-w64/x86_64-6.3.0-posix-seh-rt_v5-rev2/mingw64/bin/mingw32-make.exe
-f CMakeFiles\cmTC_8c052.dir\build.make CMakeFiles/cmTC_8c052.dir/build
mingw32-make.exe[1]: Entering directory
'D:/git/myTestBuild/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_8c052.dir/testCCompiler.c.obj
"C:\Program Files (x86)\GNU Tools ARM Embedded\6
2017-q1-update\bin\arm-none-eabi-gcc.exe" -o
CMakeFiles\cmTC_8c052.dir\testCCompiler.c.obj -c
D:\git\myTestBuild\build\CMakeFiles\CMakeTmp\testCCompiler.c
Linking C executable cmTC_8c052
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script
CMakeFiles\cmTC_8c052.dir\link.txt --verbose=1
"C:\Program Files (x86)\GNU Tools ARM Embedded\6
2017-q1-update\bin\arm-none-eabi-gcc.exe"
CMakeFiles/cmTC_8c052.dir/testCCompiler.c.obj -o cmTC_8c052
c:/program files (x86)/gnu tools arm embedded/6
2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/lib\libc.a(lib_a-exit.o):
In function `exit':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\cmTC_8c052.dir\build.make:96: recipe for target 'cmTC_8c052'
failed
mingw32-make.exe[1]: *** [cmTC_8c052] Error 1
mingw32-make.exe[1]: Leaving directory
'D:/git/myTestBuild/build/CMakeFiles/CMakeTmp'
Makefile:125: recipe for target 'cmTC_8c052/fast' failed
mingw32-make.exe: *** [cmTC_8c052/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:5 (project)
它失败了。编译器无法链接简单的演示程序,因为它没有找到“_exit”符号。 adding "--specs=nosys.specs" 应该可以解决这个问题.好像不行。
有什么想法吗?
最佳答案
将我的评论变成答案
我已经尝试了您示例的简化版本。我可以重现您的初始错误并可以通过设置 CMAKE_TRY_COMPILE_TARGET_TYPE
修复编译器检测到 STATIC_LIBRARY
。但是构建“可执行文件”仍然会失败。
所以你可以设置CMAKE_EXE_LINKER_FLAGS_INIT
到 --specs=nosys.specs
(因为那些是链接器标志)。如果您使用 ..._INIT
标志,只需确保从一个空的二进制输出目录开始,因为生成的 CMAKE_EXE_LINKER_FLAGS
已被缓存。
我更喜欢强制结果 CMAKE_EXE_LINKER_FLAGS
变量(INTERNAL
确实暗示 FORCE
)。
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(testApp)
file(WRITE main.cpp "int main(void) { return 0; }")
set(testApp "testApp")
list(
APPEND testApp_sources
main.cpp
)
add_executable(
${testApp}
${testApp_sources}
)
工具链.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")
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)
是否:
build> cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE:PATH="..\toolchain.cmake" ..
-- The C compiler identification is GNU 6.3.1
-- The CXX compiler identification is GNU 6.3.1
-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe
-- Check for working C compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe
-- Check for working CXX compiler: C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q1-update/bin/arm-none-eabi-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: build
build> cmake --build .
Scanning dependencies of target testApp
[ 50%] Building CXX object CMakeFiles/testApp.dir/main.obj
[100%] Linking CXX executable testApp
[100%] Built target testApp
引用资料
关于windows - 如何在 Windows 上使用 cmake + arm-none-eabi 进行交叉编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43781207/
是否有任何库或框架旨在促进从另一种成熟的编程语言中构建项目? 在 C++、java 等编程语言中指定逻辑、集合和复杂规则非常容易,但在 Makefile 中完成这些事情似乎是一场艰苦的战斗。我还没有深
我有这段代码可以用 clang 编译得很好(即使使用 -Weverything),但是 gcc 会发出错误。 #include #include #include using namespace
我有以下 block 头文件 BKE_mesh.h: /* Connectivity data */ typedef struct IndexNode { struct IndexNode *
我在我的一个项目中遇到了一个奇怪的问题。我的代码库依赖于一个外部库,其中包含一个名为 Dataset 的类. Dataset类私有(private)继承自 std::vector (其中 Sample
当使用 gcc、g++ 或 make 在终端中编译一个小型 C 或 C++ 项目时,我收到以下错误: /tmp/ccG1caGi.o: In function `main': main.c:(.tex
我正在尝试从 CVS 为 Windows 上的 Emacs 23.1.50 编译 CEDET,但在“第 6 步:打开 EDE...”时出现错误:“defvar:作为变量的符号值是无效的:cedet-m
我正在(重新)学习编程,我从 C 开始。我的 IDE(如果我可以这么说)是 Windows7 上的 cygwin(32 位)和 Visual-Studio 2010。我总是编译我用 gcc (cygw
我喜欢在模板类中使用本地类来执行类似“static if”的构造。但是我遇到了 gcc 4.8 不想编译我的代码的问题。但是 4.7 可以。 这个例子: #include #include #in
我有一个项目,必须仅使用 java 1.4 进行编译。但我计划使用mockito 编写一些单元测试。我想要一种在 pom 中指定的方法,以便 src/main/java 使用 jdk 1.4 编译,但
我想了解 PHP 编译过程是如何工作的。 假设我有一个名为funcs.php 的文件并且这个文件有三个函数,如果我include 或require 它,所有的在文件加载期间编译三个函数?或者源代码会被
编译工具链 我们写程序的时候用的都是集成开发环境 (IDE: Integrated Development Environment),集成开发环境可以极大地方便我们程序员编写程序,但是配置起来
当我编写一些 Scala 代码时,在尝试编译代码时收到一条奇怪的错误消息。我将代码分解为一个更简单的代码(从语义的角度来看这完全没有意义,但仍然显示了错误)。 scala> :paste // Ent
我正在编译一个 SCSS 文件,它似乎删除了我的评论。我可以使用什么命令来保留所有评论? >SASS input.scss output.css 我在 SCSS 中看到两种类型的注释。 // Comm
这是我的代码: #include typedef struct { const char *description; float value; int age; } swag
当您编译 grails war 时,我知道 .groovy 代码被编译为字节码类文件,但我不明白容器(例如 tomcat)如何在请求 GSP 时知道如何编译它们。容器了解 GSP 吗?安装在服务器上的
我正在努力将多个文件编译成一个通用程序。我收到一个错误: undefined reference to 'pi' 这是我的代码和 Makefile 的框架。我做错了什么?谢谢! 文件:calcPi.c
我尝试使用 LD_PRELOAD 来 Hook sprintf function ,所以我将打印到缓冲区的结果: #define _GNU_SOURCE #include #include int
我正在寻找最简单的方法来自动将 CoffeeScript 重新编译为 JS。 阅读documentation但仍然很难得到我想要的东西。 我需要它来监视文件夹 src/ 中的任何 *.coffee 文
我想使用定制waveformjs 。我发现this on SO但是,我不知道如何编译/安装波形来开始。我从 GitHub 克隆它并进行了更改,但是我不知道如何将其转换为 .js 文件。 最佳答案 为了
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我是一名优秀的程序员,十分优秀!