c++ - 编译包含boost库和google测试的项目时出现问题
问题描述
我有一个使用 boost::gregorian::date 的项目。我想使用 gtest 库添加一些单元测试。到目前为止,我刚刚将 gtest 库添加到我的项目中,但我还没有添加任何测试。当我尝试编译我的项目时,我遇到了一些链接器错误。当我在 Makefile (当然,在其他文件中)与 boost 相关的行中评论时,我没有错误。当我在与 gtest 相关的 Makefile 行中评论时,我只收到警告:
warning: /usr/lib/x86_64-linux-gnu/libboost_date_time.so: not a directory
但该程序按我的意愿工作。
当我尝试使用 boost 和 gtest 库编译代码时,出现错误:
cc1plus: error: /usr/lib/x86_64-linux-gnu/libboost_date_time.so: not a directory [-Werror]
cc1plus: all warnings being treated as errors
lib/googletest-master/googletest/CMakeFiles/gtest.dir/build.make:62: recipe for target 'lib/googletest-master/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o' failed
make[3]: *** [lib/googletest-master/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o] Error 1
CMakeFiles/Makefile2:282: recipe for target 'lib/googletest-master/googletest/CMakeFiles/gtest.dir/all' failed
make[2]: *** [lib/googletest-master/googletest/CMakeFiles/gtest.dir/all] Error 2
CMakeFiles/Makefile2:85: recipe for target 'CMakeFiles/planner.dir/rule' failed
make[1]: *** [CMakeFiles/planner.dir/rule] Error 2
Makefile:164: recipe for target 'planner' failed
make: *** [planner] Error 2
这是我的Makefile:
cmake_minimum_required(VERSION 3.10)
project(planner)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-std=c++14 -Wall -Wextra -pedantic")
add_executable(planner [some files])
#boost
find_package(Boost)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif ()
if (Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
set(BOOST_INCLUDE_DIRS "/usr/include")
set(BOOST_LIBRARY_DIRS "/usr/lib")
find_package(Boost REQUIRED date_time)
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${Boost_LIBRARIES})
target_link_libraries(planner ${Boost_LIBRARIES})
endif ()
#end boost
#gtest
add_subdirectory(lib/googletest-master)
include_directories(lib/googletest-master/googletest/include)
include_directories(lib/googletest-master/googlemock/include)
target_link_libraries(planner gtest gtest_main)
#end gtest
#cppconn
target_link_libraries(planner mysqlcppconn)
我正在使用 CLion 2019.1.4。你能帮我解决这个问题吗?非常感谢您的任何帮助。
解决方案
推荐阅读
- database - 如何在 neo4j 密码中仅与一个节点(具有相似名称)创建关系?
- kdb - 根据现有列向 kdb 中的表添加列?
- wordpress - 图像网格不会通过内部主页链接单击加载全屏
- python - 使用带有子集的 iterrows 操作数据框
- python - 如何在 SQLAlchemy 上声明 Postgres 函数?
- python-3.x - Spyder3安装问题:Segmentation fault (core dumped)
- plot - 在笔记本中显示 julia 中的图(使用 juliaBox)
- php - 拉拉维尔 | 检索具有关系的集合,但特定 ID 除外
- python - python中是否有用于分类数据的聚合列表函数
- python - 计算字符串Python3.6中子字符串实例的最快方法