错误LNK2019:未解析的外部符号 - 我做错了什么?

时间:2011-08-16 01:10:40

标签: c++ visual-studio

当我尝试构建项目时,我收到以下错误:

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

我完全难过,开始变得有点沮丧,我忽略了什么?

1 个答案:

答案 0 :(得分:1)

您收到链接器错误。 很可能你没有生成Geometry.cpp

的目标代码

现在可以使用:

  1. 创建一个空项目;
  2. 复制headerfiles文件夹中的头文件
  3. 复制cpp文件夹中的cpp文件
  4. 然后构建项目;

    这也将构建您的Geometry.cpp程序。