我試圖編譯在我的Ubuntu的VMware(16.04 LTS)在/ usr/bin中/ LD:無法在Ubuntu上找到-lgmock運行時gmock程序
簡單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)
這些是我遵循編譯步驟 -
[email protected]:~/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
[email protected]:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$
,之後當我的確讓我面對這個問題
[email protected]:~/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
[email protected]:~/Desktop/for_gtest/ajay/gtest/ajay/demo/gmock/simple_demo$
我不知道爲什麼會這樣「的/ usr /斌/勞工處:找不到-lgmock」問題是,即使我已經安裝了gmock未來成功。
我能夠運行gtest程序,但是當我添加gmock時,我得到了這個問題。
請幫我解決。
讓我知道更多的信息。
你能顯示用於鏈接編輯的確切行嗎(使VERBOSE = 1)? –
哪一行?我想我已經添加了所有用於編譯代碼的文件和行。你能幫我理解你在找什麼,我錯過了嗎? – user2564083