繁体   English   中英

如何将 Google 测试库链接到 CLion 项目 (Mac OS X El Capitan)

[英]How to link Google Test library to CLion project (Mac OS X El Capitan)

我正在尝试将我的项目与谷歌 C++ 测试框架联系起来。 我使用 Mac OS X El Capitan,并且在默认路径中安装了测试库。

lib

/usr/local/lib/libgtest_main.a
/usr/local/lib/libgtest.a

include (对于标题):

/usr/local/include/gtest

我创建了一个新的 CLion (2016.1.1) 项目,这是应该包含 lib 的CMakeList.txt

cmake_minimum_required(VERSION 3.5)
project(GoogleTest)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(GoogleTest ${SOURCE_FILES})
target_link_libraries(GoogleTest gtest gtest_main)

这是结果:

Scanning dependencies of target GoogleTest
[ 50%] Building CXX object CMakeFiles/GoogleTest.dir/main.cpp.o
[100%] Linking CXX executable GoogleTest
ld: library not found for -lgtest
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [GoogleTest] Error 1
make[1]: *** [CMakeFiles/GoogleTest.dir/all] Error 2
make: *** [all] Error 2

我怎样才能解决这个问题? 提前致谢

看起来/usr/local/lib不在编译器的库路径列表中。 尝试为target_link_libraries的库指定完整路径。

target_link_libraries(GoogleTest /usr/local/lib/libgtest.a /usr/local/lib/libgtest_main.a)

由于您可能有多个项目,具体取决于不同的GoogleTest版本,因此您可能要避免集中安装测试库作为构建系统。

这是一个示例设置 ,其中包含相关项目中的所有依赖项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM