Visual C++ LNK2019 error

99封情书 提交于 2019-12-24 03:04:08

问题


Using Microsoft Visual C++ I am trying to compile the file "test.cc" which is part of a small package available for free download at

http://sourceforge.net/projects/clippoly/files/

The file test.cc appears as follows:

//    nclip: a polygon clip library

//    Copyright (C) 1993  University of Twente

//    klamer@mi.el.utwente.nl

//    This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU Library General Public
//    License as published by the Free Software Foundation; either
//    version 2 of the License, or (at your option) any later version.

//    This library is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//    Library General Public License for more details.

//    You should have received a copy of the GNU Library General Public
//    License along with this library; if not, write to the Free
//    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include <cstring>
#include <iostream>

#include "poly.h"
#include "poly_io.h"
#include "nclip.h"

using namespace ::std;

void
clear(PolyPList &l)
{
    PolyPListIter i(l);
    while(i())
        delete i.val();
}

int
main(int, char *[])
{
    Poly *a = read_poly(cin), *b = read_poly(cin);
    PolyPList a_min_b, b_min_a, a_and_b;

    clip_poly( *a, *b, a_min_b, b_min_a, a_and_b );

    cout << "a_min_b:\n" << a_min_b;
    cout << "b_min_a:\n" << b_min_a;
    cout << "a_and_b:\n" << a_and_b;

    delete  a;
    delete  b;

    clear(a_min_b);
    clear(b_min_a);
    clear(a_and_b);

    return 0;
}

The test file is designed to demonstrate calculation of the intersection of two input polygons.

I have included paths to the necessary header files in 'Project->Properties->VC++ Directories->Include Directories' and the compiler is recognizing the existence of "poly.h", "poly_io.h" and "nclip.h".

however when I try compile I get the following linker errors:

test.obj : error LNK2019: unresolved external symbol "private: __thiscall PolyNode::~PolyNode(void)" (??1PolyNode@@AAE@XZ) referenced in function "private: void * __thiscall PolyNode::scalar deleting destructor'(unsigned int)"` (??_GPolyNode@@AAEPAXI@Z)

test.obj : error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Set<class Poly *> const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABV?$Set@PAVPoly@@@@@Z) referenced in function _main

test.obj : error LNK2019: unresolved external symbol "void __cdecl clip_poly(class Poly const &,class Poly const &,class Set<class Poly *> &,class Set<class Poly *> &,class Set<class Poly *> &)" (?clip_poly@@YAXABVPoly@@0AAV?$Set@PAVPoly@@@@11@Z) referenced in function _main

test.obj : error LNK2019: unresolved external symbol "class Poly * __cdecl read_poly(class std::basic_istream<char,struct std::char_traits<char> > &)" (?read_poly@@YAPAVPoly@@AAV?$basic_istream@DU?$char_traits@D@std@@@std@@@Z) referenced in function _main

What am I doing wrong? I've tried to add paths all over the place under 'Project->Properties'. But now I am at a loss.

I hope this is a fairly simple question for someone :)


回答1:


It looks as though you have told the compiler where the header files are, but not told the linker where it can find the library that contains the Poly class.

I don't have Visual Studio in front of me so the following route through the interface might not be spot on, but from memory you need to add the library (.lib) through Project->Properties->Linker->Input->Additional Dependencies.



来源:https://stackoverflow.com/questions/7828136/visual-c-lnk2019-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!