我是新到谷歌测试framework.This是我的第一个谷歌测试测试项目,我做了像这个网站gtest.php的配置,但我改变了我的way.Now上的.cpp文件,上面的链接错误出现了。
我的输出如下
1>LINK :警告LNK4068:未指定/MACHINE;默认为X86 1> GoogleTest.vcxproj -> D:\My Document\cpp\GoogleTest\Debug\GoogleTest.lib 3>3>unittest_cube.obj : error LNK2019:未解决的外部符号"public: double __thiscall Cube::Cube(Double)“(?3>unittest_cube.obj@Cube@@QAENN@Z)引用的函数”私有:虚空__thiscall testMath_myCubeTest_Test::TestBody( void )“(?TestBody@testMath_myCubeTest_Test@@EAEXXZ) 3>D:\My LNK1120:致命错误LNK1120:1未解决的外部变量==========重建:2成功,1失败,0跳过==========
如何修复此链接错误。提前谢谢。
我的unittest_cube.cpp文件(在测试项目中)如下所示
#include "gtest/gtest.h"
#include "simplemath.h"
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
TEST(testMath, myCubeTest)
{
Cube c;
EXPECT_EQ(1000.0, c.cubic(10));
//EXPECT_TRUE(c.cubic(2) == 8);
//ASSERT_EQ(1000.0, c.cubic(10));
}`我的SimpleMath.cpp就像
#include "simplemath.h"
#include <iostream>
using namespace std;
int main()
{
Cube c;
double num= c.cubic(10);
//cout << num;
//getchar();
return 0;
}
double Cube::cubic(double d)
{
return pow(d, 3);
}H文件就像
#include <cmath>
class Cube{
public:
double cubic(double i);
};发布于 2016-02-02 08:25:01
这里有两个问题:
SimpleMath.cpp测试(您的输出表明您正在使用Visual )。为此,在解决方案资源管理器中右键单击项目的“源文件”筛选器,选择“现有项.”,并添加文件SimpleMath.cpp。这应能解决第一个问题。main函数。这意味着在正确添加文件SimpleMath.cpp之后,您将得到另一个链接器错误。删除或注释掉SimpleMath.cpp中的主要函数,以成功构建代码。https://stackoverflow.com/questions/35145403
复制相似问题