C++ 错误LNK2019:未解析的外部符号-我做错了什么?
当我尝试构建项目时,会出现以下错误:C++ 错误LNK2019:未解析的外部符号-我做错了什么?,c++,visual-studio,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_
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生成对象代码
这将暂时奏效:
创建一个空项目李>
复制headerfiles文件夹中的头文件
复制cpp文件夹中的cpp文件
然后构建项目
这也将构建Geometry.cpp程序。显然正在编译AssignmentOneCoreTest.cpp,但Geometry.cpp似乎没有。你的建筑怎么样?从命令行?在VS内?电源打开了吗?嗯,我的意思是,链接中是否包含Geometry.o?是的,在VS中。我只是在“构建->构建解决方案”中。我如何检查Geometry.o是否包含在链接中?@Sam:Geometry.cpp是否列在解决方案的源文件中?如果是这样,那么在其属性中,文件类型
是否设置为C/C++code
?谢谢,这就解决了它。这只是VS的错误还是什么?不是。。。不是虫子。只是设置的问题。使用VS时,您将了解更多。
#include "geometry.h"
#include <iostream>
using namespace std;
double calculateLineLength(point *points)
{
...
}
point *findLongPaths(point *points, double threshold_distance)
{
...
}
#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