当我尝试构建项目时,我收到以下错误:
1>Assignment1CoreTest.obj : error LNK2019: unresolved external symbol "struct point * __cdecl findLongPaths(struct point *,double)" (?findLongPaths@@YAPAUpoint@@PAU1@N@Z) referenced in function "public: void __thiscall Geometry_CoreUnitTest::test_method(void)" (?test_method@Geometry_CoreUnitTest@@QAEXXZ)
1>Assignment1CoreTest.obj : error LNK2019: unresolved external symbol "double __cdecl calculateLineLength(struct point *)" (?calculateLineLength@@YANPAUpoint@@@Z) referenced in function "public: void __thiscall Geometry_CoreUnitTest::test_method(void)" (?test_method@Geometry_CoreUnitTest@@QAEXXZ)
1>C:\Users\user\documents\visual studio 2010\Projects\Assignment1\Debug\Assignment1.exe : fatal error LNK1120: 2 unresolved externals
我一直试图弄清楚为什么在最后一个小时左右并且完全没有进展所以我想知道是否有人能指出我正确的方向。显然我做了一些愚蠢的事情,但我无法解决问题。
这是我的AssignmentOneCoreTest.cpp:
#define BOOST_TEST_MODULE Test_Assignment1
#include <boost/test/unit_test.hpp>
#include "geometry.h"
BOOST_AUTO_TEST_CASE(Geometry_CoreUnitTest) {
point p[3] = {{0,0}, {0,3}, {0,1, true}};
point longest[2] = {{0,1}, {0,3,true}};
BOOST_CHECK_EQUAL(calculateLineLength(p), 5);
point *longest_calculated = findLongPaths(p, 1.1);
BOOST_CHECK_EQUAL(longest_calculated[1].y, longest[1].y);
delete longest_calculated;
}
Geometry.cpp:
#include "geometry.h"
#include <iostream>
using namespace std;
double calculateLineLength(point *points)
{
...
}
point *findLongPaths(point *points, double threshold_distance)
{
...
}
和Geometry.h:
#ifndef GEOMETRY_H
#define GEOMETRY_H
typedef struct {
int x;
int y;
bool end;
} point;
double calculateLineLength(point *points);
point *findLongPaths(point *points, double threshold_distance);
#endif
我完全难过,开始变得有点沮丧,我忽略了什么?
答案 0 :(得分:1)
您收到链接器错误。
很可能你没有生成Geometry.cpp
现在可以使用:
然后构建项目;
这也将构建您的Geometry.cpp程序。