柯南错误问:不正确的“clang”,不是CMake检测到的声音:'GNU',当我使用选项“-s build_type=Debug”时

yks3o0rb  于 2022-11-24  发布在  其他
关注(0)|答案(2)|浏览(98)

在我的项目中,我尝试用conan来管理gtest包。conanfile.txt如下:

[requires]  
gtest/1.10.0  

[generators]  
cmake

我的CMakeLists.txt如下:

cmake_minimum_required(VERSION 3.5)

project(TinyWebServer)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_STANDARD 11)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
    add_compile_options(-Wthread-safety )
endif()

add_compile_options(
 # -DVALGRIND
 -DCHECK_PTHREAD_RETURN_VALUE
 -D_FILE_OFFSET_BITS=64
 -Wall
 -Wno-unused-parameter
 -Woverloaded-virtual
 -Wpointer-arith
 -Wwrite-strings
 )

enable_testing()

add_subdirectory(Logger)
add_subdirectory(Tools)
add_subdirectory(Pools)
add_subdirectory(Http)
add_subdirectory(Timer)
add_subdirectory(Net)
add_subdirectory(Test)  

add_executable(${PROJECT_NAME} main.cc Config.cc)
target_link_libraries(${PROJECT_NAME}
    Threads::Threads
    Log::lib
    Tools::lib
    Pools::lib
    Http::lib
    Net::lib
    Timer::lib
)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_SOURCE_DIR})

当我使用如下所示的命令来构建我的项目时,一切都很顺利。

mkdir -p build/
cd build/
conan install .. --build missing -s compiler=clang -s compiler.version=3.8 -s compiler.libcxx=libstdc++11 -s build_type=Release
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
make install -j4

但是当我将build_type选项从Release切换到Debug时,就像这样:

conan install .. --build missing -s compiler=clang -s compiler.version=3.8 -s compiler.libcxx=libstdc++11 -s build_type=Debug

我收到一些错误消息:

phoenix@phoenix-virtual-machine:~/MyProject/MyTinyWebServer/build$ conan install .. --build missing -s compiler=clang -s compiler.version=3.8 -s compiler.libcxx=libstdc++11 -s build_type=Debug
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=clang
compiler.libcxx=libstdc++11
compiler.version=3.8
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

gtest/1.10.0: WARN: Package is corrupted, removing folder: /home/phoenix/.conan/data/gtest/1.10.0/_/_/package/d5608ac34c43db836b618b9cfd33cb77c7dec959
conanfile.txt: Installing package
Requirements
    gtest/1.10.0 from 'conan-center' - Cache
Packages
    gtest/1.10.0:d5608ac34c43db836b618b9cfd33cb77c7dec959 - Build

Installing (downloading, building) binaries...
gtest/1.10.0: WARN: Build folder is dirty, removing it: /home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959
gtest/1.10.0: Copying sources to build folder
gtest/1.10.0: Building your package in /home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959
gtest/1.10.0: Generator cmake created conanbuildinfo.cmake
gtest/1.10.0: Calling build()
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- 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: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Conan: called by CMake conan helper
-- Conan: called inside local cache
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Conan: Adjusting fPIC flag (ON)
CMake Error at conanbuildinfo.cmake:578 (message):
  Incorrect 'clang', is not the one detected by CMake: 'GNU'
Call Stack (most recent call first):
  conanbuildinfo.cmake:141 (conan_check_compiler)
  CMakeLists.txt:5 (conan_basic_setup)

-- Configuring incomplete, errors occurred!
See also "/home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959/CMakeFiles/CMakeOutput.log".
gtest/1.10.0: 
gtest/1.10.0: ERROR: Package 'd5608ac34c43db836b618b9cfd33cb77c7dec959' build failed
gtest/1.10.0: WARN: Build folder /home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959
ERROR: gtest/1.10.0: Error in build() method, line 59
    cmake = self._configure_cmake()
while calling '_configure_cmake', line 53
    cmake.configure()
    ConanException: Error 1 while executing cd '/home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959' && cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Debug" -DCONAN_IN_LOCAL_CACHE="ON" -DCONAN_COMPILER="clang" -DCONAN_COMPILER_VERSION="3.8" -DCONAN_CXX_FLAGS="-m64" -DCONAN_SHARED_LINKER_FLAGS="-m64" -DCONAN_C_FLAGS="-m64" -DCONAN_LIBCXX="libstdc++11" -DBUILD_SHARED_LIBS="OFF" -DCMAKE_INSTALL_PREFIX="/home/phoenix/.conan/data/gtest/1.10.0/_/_/package/d5608ac34c43db836b618b9cfd33cb77c7dec959" -DCMAKE_INSTALL_BINDIR="bin" -DCMAKE_INSTALL_SBINDIR="bin" -DCMAKE_INSTALL_LIBEXECDIR="bin" -DCMAKE_INSTALL_LIBDIR="lib" -DCMAKE_INSTALL_INCLUDEDIR="include" -DCMAKE_INSTALL_OLDINCLUDEDIR="include" -DCMAKE_INSTALL_DATAROOTDIR="share" -DCONAN_CMAKE_POSITION_INDEPENDENT_CODE="ON" -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY="ON" -DCONAN_EXPORTED="1" -DCUSTOM_DEBUG_POSTFIX="d" -DBUILD_GMOCK="True" -DGTEST_NO_MAIN="False" -Dgtest_hide_internal_symbols="False" -Wno-dev '/home/phoenix/.conan/data/gtest/1.10.0/_/_/build/d5608ac34c43db836b618b9cfd33cb77c7dec959'

这真的让我很困惑。命令conan install .. --build missing -s compiler=clang -s compiler.version=3.8 -s compiler.libcxx=libstdc++11 -s build_type=Debug已经指定编译器是clang。但是从消息Incorrect 'clang', is not the one detected by CMake: 'GNU'来看,似乎柯南检测到了gcc编译器。为什么会发生这种情况?如果我想把我的项目构建到调试版本,我该怎么做?谢谢~

6tdlim6h

6tdlim6h1#

哦,我想我犯了一些错误。使用conan安装gtest包和构建我的项目到调试版本是完全不同的两件事。所以如果我想构建我的项目到调试版本,我应该使用这样的命令:

conan install .. --build missing -s compiler=clang -s compiler.version=3.8 -s compiler.libcxx=libstdc++11 -s build_type=Release
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug

gtest的版本是Release并不妨碍我将我的项目编译为调试版本。😅

hjqgdpho

hjqgdpho2#

1.conanfile.txt

[generators]
cmake
virtualenv

2.安装conan后,使用env

source activate.sh
cmake ..

3.退出环境

source deactivate.sh

相关问题