我正在尝试使用 cmake 进行一些交叉编译.互联网上的所有示例都很容易,我设法在 Linux(x86 和 ARM)、Windows 和 Android 上交叉编译了我的库.但现在我想在自定义平台上进行.
I am trying to do some crosscompilation using cmake. Some are easy with all the examples on Internet, I managed to crosscompile my library on Linux (x86 and ARM), Windows and Android. But now I would like to do it on a custom platform.
我需要实现的过程:
但是 Cmake 正在测试我的自定义 C/C++ 库中的符号,这使我的库无法编译.我遇到的错误是 cmake 某些版本的 GLIBCXX 和 CXXABI(没有 C 问题)但不是全部.
But Cmake is testing for symbols in my custom C/C++ libraries which make my library unable to compile. The errors I have are that cmake some versions of GLIBCXX and CXXABI (no C issues) but not all of them.
有没有办法让 cmake 可以使用它?
Is there a way to make cmake ok with it ?
我尝试使用:
set(CMAKE_C_COMPILER_WORKS TRUE)
set(CMAKE_CXX_COMPILER_WORKS TRUE)
还有:
include(CMakeForceCompiler)
...
cmake_force_c_compiler(${ENV_PATH}/bin/${CC})
cmake_force_cxx_compiler(${ENV_PATH}/bin/${CXX})
但 cmake 仍在检查符号.
But cmake is still checking for symbols.
如果没有您的环境和错误消息,就不容易说出真正的根本原因,但这里有两个常见原因和相应的修复:
Without having your environment nor the error message it's not easy to tell the actual root cause but here are two of the common causes and respective fixes:
如果您没有完整的为您的自定义环境创建的工具链文件 - 因此 CMake 无法链接简单的测试程序 - 您可以尝试名为 CMAKE_TRY_COMPILE_TARGET_TYPE
.
If you don't have a complete toolchain file created for your custom environment - so CMake can't link a simple test program - you can try the relatively new (version 3.6) global CMake variable named CMAKE_TRY_COMPILE_TARGET_TYPE
.
所以只需添加以下内容:
So just add the following:
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
然后 CMake 会尝试构建一个静态库.
Then CMake would just try to build a static library.
要仅设置最常见的 GCC 编译器变量并仅进行一些基本检查,请尝试:
To have only the most common GCC compiler variables set and have only some basic checks, try:
SET(CMAKE_SYSTEM_NAME Generic)
参见 CMake 交叉编译:设置系统和工具链:
如果您的目标是没有操作系统的嵌入式系统,请将 CMAKE_SYSTEM_NAME 设置为通用"
If your target is an embedded system without OS set CMAKE_SYSTEM_NAME to "Generic"
参考资料
这篇关于如何部分禁用 cmake C/C++ 自定义编译器检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!