jhasse / poly2tri

2D constrained Delaunay triangulation library
BSD 3-Clause "New" or "Revised" License
439 stars 89 forks source link

Unable to build project with library #52

Closed mconicx closed 1 year ago

mconicx commented 1 year ago

I'm building this repository using CMake. Code is completely unchanged, so are the CMake settings. Building for x64 platform. Everything is fine, the project generates the static library poly2tri.lib in \out\build\x64-Debug.

I'm trying to use the library in my own C++ project. It uses OpenGL, and GLFW 3.33. I've made my own test unit:

    #include <poly2tri.h>

    std::vector<p2t::Point*> pts;
    p2t::Point* temp = nullptr;
    pts.push_back(new p2t::Point()); temp = pts[pts.size() - 1]; temp->x = 0.; temp->y = 0.;
    pts.push_back(new p2t::Point()); temp = pts[pts.size() - 1]; temp->x = 0.; temp->y = 1.;
    pts.push_back(new p2t::Point()); temp = pts[pts.size() - 1]; temp->x = 1.; temp->y = 1.;
    pts.push_back(new p2t::Point()); temp = pts[pts.size() - 1]; temp->x = 1.; temp->y = 0.;

    p2t::CDT* cdt = new p2t::CDT(pts);
    cdt->Triangulate();
    std::vector<p2t::Triangle*> tris = cdt->GetTriangles();

This is only a little example, to show what I'm trying to call from the library. The way I've linked the library to my project is as follows; Through the Solution settings of my project (The library repository is in D:\poly2tri-master\):

Headers directory C/C++ > Additional Include Directories > D:\poly2tri-master\poly2tri (including glfw3)

Library directory Linker > Additional Library Directories > D:\poly2tri-master\out\build\x64-Debug (including glfw3)

Linking Linker > Input > Additional Dependencies > opengl32.lib; glfw3.lib; poly2tri.lib

I am able to include the header file poly2tri.h, and call all the members and functions from the p2t namespace. However, when I try to build my project, I get the following error messages:

1>shadedmodel.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl p2t::Point::Point(void)" (__imp_??0Point@p2t@@QEAA@XZ) referenced in function "public: __cdecl CShadedModel::CShadedModel(void)" (??0CShadedModel@@QEAA@XZ) 1>shadedmodel.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: struct p2t::Point * __cdecl p2t::Triangle::GetPoint(int)" (__imp_?GetPoint@Triangle@p2t@@QEAAPEAUPoint@2@H@Z) referenced in function "public: __cdecl CShadedModel::CShadedModel(void)" (??0CShadedModel@@QEAA@XZ) 1>shadedmodel.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl p2t::CDT::CDT(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> > const &)" (__imp_??0CDT@p2t@@QEAA@AEBV?$vector@PEAUPoint@p2t@@V?$allocator@PEAUPoint@p2t@@@std@@@std@@@Z) referenced in function "public: __cdecl CShadedModel::CShadedModel(void)" (??0CShadedModel@@QEAA@XZ) 1>shadedmodel.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl p2t::CDT::Triangulate(void)" (__imp_?Triangulate@CDT@p2t@@QEAAXXZ) referenced in function "public: __cdecl CShadedModel::CShadedModel(void)" (??0CShadedModel@@QEAA@XZ) 1>shadedmodel.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > __cdecl p2t::CDT::GetTriangles(void)" (__imp_?GetTriangles@CDT@p2t@@QEAA?AV?$vector@PEAVTriangle@p2t@@V?$allocator@PEAVTriangle@p2t@@@std@@@std@@XZ) referenced in function "public: __cdecl CShadedModel::CShadedModel(void)" (??0CShadedModel@@QEAA@XZ)

I've built both my project and the library under x64, and I am unable to use it at all.

jhasse commented 1 year ago

Try passing -D BUILD_SHARED_LIBS=0 to CMake when building poly2tri.