仅当启用C或CXX语言时,FindThreads才起作用

时间:2019-01-24 15:14:24

标签: c++ cmake toolchain

我正在尝试构建一个可移植的gcc,以允许其他人使用不同的系统进行编译。

我使用crosstool-ng交叉编译gcc-8.2的{​​{1}},建立了一个静态工具链。

我创建了以下工具链文件:

x86_64

在我的主机上,它运行良好,可以毫无问题地进行编译,但是当我将工具链文件移到另一台计算机上时,我遇到了问题。如果我尝试在我的cmake中包含线程,则出现以下错误:

#set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(QAMF_ROOT "/opt/hyperserver-dev/x86_64-qamf")

set(COMPILER_ROOT "${QAMF_ROOT}")
set(COMPILER_PREFIX "x86_64-qamf-linux-gnu-")
set(C_COMPILER "gcc")
set(CXX_COMPILER "g++")

# specify the cross compile
set(CMAKE_C_COMPILER    ${COMPILER_ROOT}/bin/${COMPILER_PREFIX}${C_COMPILER} )
set(CMAKE_CXX_COMPILER  ${COMPILER_ROOT}/bin/${COMPILER_PREFIX}${CXX_COMPILER} )

# HyperServer sysroot path
set(HYPERSERVER_SYSROOT "${COMPILER_ROOT}/x86_64-qamf-linux-gnu/sysroot") 

# where is the target environment 
set(CMAKE_FIND_ROOT_PATH ${HYPERSERVER_SYSROOT} )

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

这是我的CMakeFiles / txt

CMake Error at /usr/local/share/cmake-3.13/Modules/FindThreads.cmake:54 (message):
  FindThreads only works if either C or CXX language is enabled
Call Stack (most recent call first):
  CMakeLists.txt:2 (find_package)


-- Configuring incomplete, errors occurred!
make: *** No targets specified and no makefile found.  Stop.

1 个答案:

答案 0 :(得分:2)

放置

find_package(Threads REQUIRED)

之后

project(HelloWorld C CXX)

这是错误消息所表明的:project()调用启用了语言,因此查找线程将成功。


通常,所有 find_package呼叫应该在 project()呼叫之后。