/usr/bin/ld:在运行gmock程序时无法在ubuntu上找到-lgmock
/usr/bin/ld: cannot find -lgmock on ubuntu while running gmock program
我正在尝试在我的ubuntu vmware(16.04 lts(上编译简单的gmock示例
进行" make"
时要低于错误我有以下文件 -
" test.h"
class CBasicMath
{
public:
CBasicMath(){}
virtual ~CBasicMath() {}
virtual int Addition(int x, int y);
virtual int Multiply(int x, int y);
virtual int Divide(int x, int y);
};
" test.cpp"
#include "test.h"
int CBasicMath::Addition(int x, int y)
{
return (x + y);
}
int CBasicMath::Multiply(int x, int y)
{
return (x * y);
}
int CBasicMath::Divide(int x, int y)
{
return (x / y);
}
" mocktest.h"
#include "gmock/gmock.h"
#include "test.cpp"
class MockBasicTest : public CBasicMath {
public:
MOCK_METHOD2(Addition, int(int x, int y));
MOCK_METHOD2(Multiply, int(int x, int y));
MOCK_METHOD2(Divide, int(int x, int y));
};
" main.cpp"
#include "mocktest.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
TEST(BasicMathTest, testAddition) {
MockBasicTest basictest;
EXPECT_CALL(basictest, Addition(2,3)).Times(0);
// EXPECT_EQ(0, basictest.Addition(2,3));
/*
.Times(5);
EXPECT_EQ(0,basictest.Addition(2,3));
EXPECT_EQ(0,basictest.Addition(2,3));
EXPECT_EQ(0,basictest.Addition(2,3));
EXPECT_EQ(0,basictest.Addition(2,3));
EXPECT_EQ(0,basictest.Addition(2,3));
*/
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
" cmakelists.txt"
cmake_minimum_required(VERSION 2.6)
# Locate GTest
find_package(GTest REQUIRED)
include_directories(${GTEST_INCLUDE_DIRS})
# Link runTests with what we want to test and the GTest and pthread library
add_executable(runTests main.cpp)
target_link_libraries(runTests -lgtest -lgmock -lpthread)
这些是我遵循的步骤 -
ajay@ubuntu:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$ cmake CMakeLists.txt
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ajay/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo
ajay@ubuntu:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$
之后,当我做出问题时,我面临问题
ajay@ubuntu:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$ make
Scanning dependencies of target runTests
make[2]: Warning: File 'main.cpp' has modification time 84978 s in the future
[ 50%] Building CXX object CMakeFiles/runTests.dir/main.cpp.o
[100%] Linking CXX executable runTests
/usr/bin/ld: cannot find -lgmock
collect2: error: ld returned 1 exit status
CMakeFiles/runTests.dir/build.make:94: recipe for target 'runTests' failed
make[2]: *** [runTests] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
ajay@ubuntu:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$
我不知道为什么这个"/usr/bin/ld:找不到-lgmock"问题即使我已经成功安装了gmock。
我能够运行GTEST程序,但是当我添加Gmock时,我会遇到此问题。
请帮助我解决。
让我知道更多信息。
查找taget_link_libraries
的文档。检查FindGtest.cmake
中的评论
您不应使用-l指定库,而是使用find_package的变量,例如${GTEST_LIBRARIES}
您尚未完成gmock的find_package,因此没有针对gmock定义的变量。因为这不是标准的CMAKE模块,请自己写或从Internet中拿一张
但是,Google测试文档建议不要使用系统中的已安装库,而是要在项目中自己构建它们。互联网上有几个示例如何将GTEST/GMOCK添加为外部Project作为CMAKE项目。
相关文章:
- 在Ubuntu 16.04上安装Cilk时出现问题
- 如何在Ubuntu中使用cmake设置qt4
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 无法将 GLFW 库与 Ubuntu 18.04 上的头文件链接
- 无法在Ubuntu上将共享库与Eclipse链接
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- 无法安装 R 包 "nloptr"(Ubuntu 16.04 上的 R3.6.2) - C++编译器问题
- 使用 ubuntu 终端在 c++ 上运行线程类的问题
- 如何在 Ubuntu 上安装 OpenCV for C/C++
- 估计 Ubuntu C++内存使用情况
- 在 Ubuntu 中创建自动安装程序
- 分段 Linux Ubuntu 中的 g++ 错误,但在 Windows 中的 g++/MingW 中,在 C++ 中打
- OpenGL 在 VMWare Fusion 版本 10.1.3 上安装的虚拟机 (Ubuntu 16.04) 上崩溃
- 在 ubuntu 上安装 node js pulsar 客户端
- 在 Ubuntu 18.04 上编译 GLSL 着色器时"不支持 GLSL 3.30"?
- 这是 ubuntu 16.04 中的 gdb 错误吗?
- 生成文件:6:目标'all'的配方在 Ubuntu-16.04 上失败
- LinuxdeployQT 今天如何创建 Appimage,自 ubuntu 16.04 发布以来,它可以在每个 Lin
- 在 Ubuntu 服务器上运行 QT 应用程序时崩溃
- /usr/bin/ld:在运行gmock程序时无法在ubuntu上找到-lgmock