【发布时间】:2017-05-22 11:50:52
【问题描述】:
我必须交叉编译使用 CMake 的第 3 方库。
为了构建一些东西,我需要将“-B path”标志传递给编译器。
foo.c:
void main(){}
构建命令:
cross-gcc -B /path/to/somewhere -o foo.o foo.c
没有“-B 路径”选项,编译器根本无法工作。
因此我在我的 cmake 工具链文件中使用以下几行:
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
但是在编译器的验证过程中,CMake 似乎没有使用我设置的标志:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /cross-path/cross-gcc
-- Check for working C compiler: /cross-path/cross-gcc -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
The C compiler "cross-path/cross-gcc" is not able
to compile a simple test program.
....
....
/cross-path/cross-gcc -o CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c CMakeFiles/CMakeTmp/testCCompiler.c
当我第二次调用 CMake 时,cross-gcc 通过了简单的编译测试,但这次 cross-g++ 失败了:
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /cross-path/cross-gcc
-- Check for working C compiler: /cross-path/cross-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /cross-path/cross-g++
-- Check for working CXX compiler: /cross-path/cross-g++ -- broken
CMake Error at /usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake:45 (MESSAGE):
The C++ compiler "/cross-path/cross-g++" is not
able to compile a simple test program.
....
....
/cross-path/cross-g++ -o CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o -c CMakeFiles/CMakeTmp/testCXXCompiler.cxx
如果我第三次调用 CMake,一切正常,只有一个警告:
....
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_TOOLCHAIN_FILE
我正在使用 CMake 2.8.7,并且知道它已经过时了,但如果是这种情况,升级不是一种选择。
编辑:
工具链文件:
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_C_FLAGS "-B /path/to/somewhere")
SET(CMAKE_CXX_FLAGS "-B /path/to/somewhere")
# specify the cross compiler
SET(CMAKE_C_COMPILER /cross-path/cross-gcc)
SET(CMAKE_CXX_COMPILER /cross-path/cross-g++)
【问题讨论】:
-
你能显示你使用的所有工具链文件吗?
-
当然,我编辑了问题。
-
我想知道在这种情况下您是否应该使用
CMAKE_FORCE_XXX_COMPILER()宏,因为您需要添加这些标志...在这里查看cmake_cross_compiling 并查找INCLUDE(CMakeForceCompiler)。 -
正是:) 我使用了以下链接中提到的方法:stackoverflow.com/questions/6476203/… 非常感谢您的提示。我不确定您是否应该将其添加为答案,或者该问题应作为重复项关闭。
-
嗯,好吧,我没看到,我只是阅读了我链接的文档......我将在答案中包含这些链接(文档和你提到的这个 SO)。
标签: cmake cross-compiling