我有一个项目在使用boost :: gregorian :: date。我想使用gtest库添加一些单元测试。到目前为止,我刚刚将gtest库添加到了我的项目中,但是还没有添加任何测试。当我尝试编译项目时,出现一些链接器错误。我在与boost相关的Makefile(当然还有其他文件)行中注释时也没有错误。当我在与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。 您能帮我解决这个问题吗?非常感谢您的帮助。