error LNK2019: unresolved external symbol - what am I doing wrong?
When I try and build my project I get the following errors:
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
I've been trying to work out why for the last hour or so and have made absolutely no progress so I was wondering if anyone might be able to point me in the right direction. Obviously I'm doing something stupid but I can't work out what.
This is my 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)
{
    ...
}
and 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
I'm totally stumpe开发者_C百科d and starting to get kinda frustrated, what am I overlooking?
you are getting linker error. 
Most probably you are not generating the object code for Geometry.cpp
this would work for now:
- create an empty project;
- copy the header files in the headerfiles folder
- copy the cpp files in the cpp files folder
then build the project;
this will build your Geometry.cpp program as well.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论