在交叉编译时,我应该怎么处理C ++库? [英] What must I do with C++ libraries on cross compilation?
问题描述
这是我的编译器部分我的配置:
Here is my compiler part of my config:
IF(UNIX)
## Compiler flags
# specify the cross compiler
SET(CMAKE_C_COMPILER /home/username/projects/buildroot/output/host/usr/bin/arm-linux-gcc)
SET(CMAKE_CXX_COMPILER /home/username/projects/buildroot/output/host/usr/bin/arm-linux-g++)
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-O3")
set(CMAKE_EXE_LINKER_FLAGS "-lsqlite3 -lrt -lpthread")
endif()
target_link_libraries(complex
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY})
ENDIF(UNIX)
有3个问题:-lsqlite3 -lrt -lpthread
There are 3 problems : -lsqlite3 -lrt -lpthread
我必须如何使它们适合我的架构,并在这里指定?
How must I to make them for my architecture and specify here? How to set (using set?) the path of compiled libraries after I will get them recompiled for my architecture somehow?
推荐答案
如果设置(使用set?)编译库的路径,你想做交叉编译与CMake你真的应该使用一个工具链文件。有关介绍,请参见 CMake Wiki 。为了使用第三方库(即不包括在交叉编译工具链中),您还需要对它们进行交叉编译。
If you want to do cross-compilation with CMake you really should use a toolchain file for that. See the CMake Wiki for an introduction. In order to use third-party libraries (i.e. not included by the cross-compilation toolchain) you need to cross-compile them too.
编辑:由于您使用buildroot工具链,您可以使用已经包含的CMake工具链文件。调用CMake时,只需传递 -DCMAKE_TOOLCHAIN_FILE = / home / username / projects / buildroot / output / toolchainfile.cmake
无需在您的 CMakeLists.txt
CMAKE_C_COMPILER 和 CMAKE_CXX_COMPILER
>文件。此外,设置 CMAKE_CXX_FLAGS
和 CMAKE_EXE_LINKER_FLAGS
被认为是非常糟糕的做法。
Edit: Since you are using the buildroot toolchain, you can use the already included CMake toolchain file. Just pass -DCMAKE_TOOLCHAIN_FILE=/home/username/projects/buildroot/output/toolchainfile.cmake
when invoking CMake. No need to set CMAKE_C_COMPILER
and CMAKE_CXX_COMPILER
in your CMakeLists.txt
file. Also, setting CMAKE_CXX_FLAGS
and CMAKE_EXE_LINKER_FLAGS
is considered to be very bad practice.
据推测,在构建buildroot工具链时,您已经构建了sqlite3,因此您可以像任何其他库一样使用它。 Ie:
Presumably you have built sqlite3 while building the buildroot toolchain, so you can use it just like any other library. I.e:
find_path(SQLITE3_INCLUDE_DIR sqlite3.h)
find_library(SQLITE3_LIBRARY sqlite3)
if(NOT SQLITE3_INCLUDE_DIR)
message(SEND_ERROR "Failed to find sqlite3.h")
endif()
if(NOT SQLITE3_LIBRARY)
message(SEND_ERROR "Failed to find the sqlite3 library")
endif()
find_package(Threads REQUIRED)
# ...
target_link_libraries(complex
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${SQLITE3_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
rt)
最后,不要将 CMAKE_CXX_FLAGS
设置为 -O3
。在配置项目时,用户应该传递 -DCMAKE_BUILD_TYPE = Release
。
Lastly, do not set CMAKE_CXX_FLAGS
to -O3
. The user should pass -DCMAKE_BUILD_TYPE=Release
when configuring the project instead.
这篇关于在交叉编译时,我应该怎么处理C ++库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!