CMake 在 Ubuntu 中找不到 GoogleTest 所需的库

2023-08-27C/C++开发问题
10

本文介绍了CMake 在 Ubuntu 中找不到 GoogleTest 所需的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

类似问题此处.

这是我的 CMakeLists.txt:

This is my CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})

# Add test cpp file
add_executable(foo foo.cpp)

# Link test executable against gtest & gtest_main
target_link_libraries(foo ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread)

还有我的 foo.cpp:

And my foo.cpp:

#include <gtest/gtest.h>

TEST(sample_test_case, sample_test)
{
    EXPECT_EQ(1, 1);
}

int main(int argc, char **argv)
{
    testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

现在,使用 g++ 编译器时一切正常.但是,在尝试使用 QNX 的编译器 ntox86-c++ 时,我遇到了这个问题:

Now, all works fine when using the g++ compiler. However, when attempting to use QNX's compiler, ntox86-c++, I run into this problem:

CMake 错误在/usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):找不到 GTest(丢失:GTEST_LIBRARY GTEST_INCLUDE_DIRGTEST_MAIN_LIBRARY)

CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE): Could NOT find GTest (missing: GTEST_LIBRARY GTEST_INCLUDE_DIR GTEST_MAIN_LIBRARY)

我在 Ubuntu 上使用 ntox86-c++ 编译器、googletest 和 cmake-gui.

I am on Ubuntu using the ntox86-c++ compiler, googletest, and cmake-gui.

是什么?

推荐答案

Google test 可能没有正确安装(libgtest-dev 可能只安装需要编译的源文件).我遇到了同样的问题,我按照 http://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/

Google test was probably not properly installed (libgtest-dev may install only source files that needed to be compiled). I had the same problem and I followed the instructions from http://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/

sudo apt-get install libgtest-dev
sudo apt-get install cmake # install cmake
cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make

#copy or symlink libgtest.a and libgtest_main.a to your /usr/lib folder
sudo cp *.a /usr/lib

这对我有用.

这篇关于CMake 在 Ubuntu 中找不到 GoogleTest 所需的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6