jhasse / poly2tri

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

Failed to build my own project with self-built lib file... #51

Closed mconicx closed 1 year ago

mconicx commented 1 year ago

I'm using Visual Studio 2022, building for Windows 10 Enterprise LTSC x64

I am able to open the poly2tri project via Visual Studio, and build the library file. However, when linking to my project, I get the following build errors:

1>Generating Code... 1> Creating library C:\Users\MCX\source\repos\Poly2Tri-Test\x64\Debug\Poly2Tri-Test.lib and object C:\Users\MCX\source\repos\Poly2Tri-Test\x64\Debug\Poly2Tri-Test.exp 1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>LINK : warning LNK4217: symbol '??0Triangle@p2t@@QEAA@AEAUPoint@1@00@Z (public: __cdecl p2t::Triangle::Triangle(struct p2t::Point &,struct p2t::Point &,struct p2t::Point &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::Fill(class p2t::SweepContext &,struct p2t::Node &)" (?Fill@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUNode@2@@Z)' 1>LINK : warning LNK4286: symbol '??0Triangle@p2t@@QEAA@AEAUPoint@1@00@Z (public: __cdecl p2t::Triangle::Triangle(struct p2t::Point &,struct p2t::Point &,struct p2t::Point &))' defined in 'shapes.obj' is imported by 'sweep_context.obj' 1>LINK : warning LNK4217: symbol '?PointCW@Triangle@p2t@@QEAAPEAUPoint@2@AEBU32@@Z (public: struct p2t::Point * __cdecl p2t::Triangle::PointCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4286: symbol '?PointCW@Triangle@p2t@@QEAAPEAUPoint@2@AEBU32@@Z (public: struct p2t::Point * __cdecl p2t::Triangle::PointCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep_context.obj' 1>LINK : warning LNK4217: symbol '?PointCCW@Triangle@p2t@@QEAAPEAUPoint@2@AEBU32@@Z (public: struct p2t::Point * __cdecl p2t::Triangle::PointCCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?OppositePoint@Triangle@p2t@@QEAAPEAUPoint@2@AEAV12@AEBU32@@Z (public: struct p2t::Point * __cdecl p2t::Triangle::OppositePoint(class p2t::Triangle &,struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::FlipEdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?FlipEdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?MarkNeighbor@Triangle@p2t@@QEAAXAEAV12@@Z (public: void __cdecl p2t::Triangle::MarkNeighbor(class p2t::Triangle &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::Fill(class p2t::SweepContext &,struct p2t::Node &)" (?Fill@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUNode@2@@Z)' 1>LINK : warning LNK4217: symbol '?MarkConstrainedEdge@Triangle@p2t@@QEAAXH@Z (public: void __cdecl p2t::Triangle::MarkConstrainedEdge(int))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: bool __cdecl p2t::Sweep::IsEdgeSideOfTriangle(class p2t::Triangle &,struct p2t::Point &,struct p2t::Point &)" (?IsEdgeSideOfTriangle@Sweep@p2t@@AEAA_NAEAVTriangle@2@AEAUPoint@2@1@Z)' 1>LINK : warning LNK4217: symbol '?MarkConstrainedEdge@Triangle@p2t@@QEAAXPEAUPoint@2@0@Z (public: void __cdecl p2t::Triangle::MarkConstrainedEdge(struct p2t::Point *,struct p2t::Point *))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?Index@Triangle@p2t@@QEAAHPEBUPoint@2@@Z (public: int __cdecl p2t::Triangle::Index(struct p2t::Point const *))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: bool __cdecl p2t::Sweep::Legalize(class p2t::SweepContext &,class p2t::Triangle &)" (?Legalize@Sweep@p2t@@AEAA_NAEAVSweepContext@2@AEAVTriangle@2@@Z)' 1>LINK : warning LNK4217: symbol '?EdgeIndex@Triangle@p2t@@QEAAHPEBUPoint@2@0@Z (public: int __cdecl p2t::Triangle::EdgeIndex(struct p2t::Point const *,struct p2t::Point const *))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: bool __cdecl p2t::Sweep::IsEdgeSideOfTriangle(class p2t::Triangle &,struct p2t::Point &,struct p2t::Point &)" (?IsEdgeSideOfTriangle@Sweep@p2t@@AEAA_NAEAVTriangle@2@AEAUPoint@2@1@Z)' 1>LINK : warning LNK4217: symbol '?NeighborAcross@Triangle@p2t@@QEAAPEAV12@AEBUPoint@2@@Z (public: class p2t::Triangle * __cdecl p2t::Triangle::NeighborAcross(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?NeighborCW@Triangle@p2t@@QEAAPEAV12@AEBUPoint@2@@Z (public: class p2t::Triangle * __cdecl p2t::Triangle::NeighborCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?NeighborCCW@Triangle@p2t@@QEAAPEAV12@AEBUPoint@2@@Z (public: class p2t::Triangle * __cdecl p2t::Triangle::NeighborCCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::EdgeEvent(class p2t::SweepContext &,struct p2t::Point &,struct p2t::Point &,class p2t::Triangle *,struct p2t::Point &)" (?EdgeEvent@Sweep@p2t@@AEAAXAEAVSweepContext@2@AEAUPoint@2@1PEAVTriangle@2@1@Z)' 1>LINK : warning LNK4217: symbol '?GetConstrainedEdgeCCW@Triangle@p2t@@QEAA_NAEBUPoint@2@@Z (public: bool __cdecl p2t::Triangle::GetConstrainedEdgeCCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?GetConstrainedEdgeCW@Triangle@p2t@@QEAA_NAEBUPoint@2@@Z (public: bool __cdecl p2t::Triangle::GetConstrainedEdgeCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::FinalizationPolygon(class p2t::SweepContext &)" (?FinalizationPolygon@Sweep@p2t@@AEAAXAEAVSweepContext@2@@Z)' 1>LINK : warning LNK4217: symbol '?SetConstrainedEdgeCCW@Triangle@p2t@@QEAAXAEBUPoint@2@_N@Z (public: void __cdecl p2t::Triangle::SetConstrainedEdgeCCW(struct p2t::Point const &,bool))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?SetConstrainedEdgeCW@Triangle@p2t@@QEAAXAEBUPoint@2@_N@Z (public: void __cdecl p2t::Triangle::SetConstrainedEdgeCW(struct p2t::Point const &,bool))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?GetDelunayEdgeCCW@Triangle@p2t@@QEAA_NAEBUPoint@2@@Z (public: bool __cdecl p2t::Triangle::GetDelunayEdgeCCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?GetDelunayEdgeCW@Triangle@p2t@@QEAA_NAEBUPoint@2@@Z (public: bool __cdecl p2t::Triangle::GetDelunayEdgeCW(struct p2t::Point const &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?SetDelunayEdgeCCW@Triangle@p2t@@QEAAXAEBUPoint@2@_N@Z (public: void __cdecl p2t::Triangle::SetDelunayEdgeCCW(struct p2t::Point const &,bool))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?SetDelunayEdgeCW@Triangle@p2t@@QEAAXAEBUPoint@2@_N@Z (public: void __cdecl p2t::Triangle::SetDelunayEdgeCW(struct p2t::Point const &,bool))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?Legalize@Triangle@p2t@@QEAAXAEAUPoint@2@0@Z (public: void __cdecl p2t::Triangle::Legalize(struct p2t::Point &,struct p2t::Point &))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?ClearNeighbors@Triangle@p2t@@QEAAXXZ (public: void __cdecl p2t::Triangle::ClearNeighbors(void))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: void __cdecl p2t::Sweep::RotateTrianglePair(class p2t::Triangle &,struct p2t::Point &,class p2t::Triangle &,struct p2t::Point &)const " (?RotateTrianglePair@Sweep@p2t@@AEBAXAEAVTriangle@2@AEAUPoint@2@01@Z)' 1>LINK : warning LNK4217: symbol '?ClearDelunayEdges@Triangle@p2t@@QEAAXXZ (public: void __cdecl p2t::Triangle::ClearDelunayEdges(void))' defined in 'shapes.obj' is imported by 'sweep.obj' in function '"private: class p2t::Triangle & __cdecl p2t::Sweep::NextFlipTriangle(class p2t::SweepContext &,int,class p2t::Triangle &,class p2t::Triangle &,struct p2t::Point &,struct p2t::Point &)" (?NextFlipTriangle@Sweep@p2t@@AEAAAEAVTriangle@2@AEAVSweepContext@2@HAEAV32@1AEAUPoint@2@2@Z)' 1>LINK : warning LNK4217: symbol '??0Point@p2t@@QEAA@NN@Z (public: __cdecl p2t::Point::Point(double,double))' defined in 'shapes.obj' is imported by 'sweep_context.obj' in function '"private: void __cdecl p2t::SweepContext::InitTriangulation(void)" (?InitTriangulation@SweepContext@p2t@@AEAAXXZ)' 1>shapes.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 "bool __cdecl p2t::IsDelaunay(class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > const &)" (?IsDelaunay@p2t@@YA_NAEBV?$vector@PEAVTriangle@p2t@@V?$allocator@PEAVTriangle@p2t@@@std@@@std@@@Z) 1>sweep.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct p2t::Point * __cdecl p2t::Triangle::GetPoint(int)" (__imp_?GetPoint@Triangle@p2t@@QEAAPEAUPoint@2@H@Z) 1>sweep_context.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: struct p2t::Point * __cdecl p2t::Triangle::GetPoint(int)" (__imp_?GetPoint@Triangle@p2t@@QEAAPEAUPoint@2@H@Z) 1>shapes.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl p2t::Triangle::Contains(struct p2t::Point const *,struct p2t::Point const *)" (__imp_?Contains@Triangle@p2t@@QEAA_NPEBUPoint@2@0@Z) referenced in function "public: void __cdecl p2t::Triangle::MarkNeighbor(class p2t::Triangle &)" (?MarkNeighbor@Triangle@p2t@@QEAAXAEAV12@@Z) 1>sweep.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __cdecl p2t::Triangle::Contains(struct p2t::Point const *,struct p2t::Point const *)" (__imp_?Contains@Triangle@p2t@@QEAA_NPEBUPoint@2@0@Z) 1>sweep.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class p2t::Triangle * __cdecl p2t::Triangle::GetNeighbor(int)" (__imp_?GetNeighbor@Triangle@p2t@@QEAAPEAV12@H@Z) referenced in function "private: bool __cdecl p2t::Sweep::IsEdgeSideOfTriangle(class p2t::Triangle &,struct p2t::Point &,struct p2t::Point &)" (?IsEdgeSideOfTriangle@Sweep@p2t@@AEAA_NAEAVTriangle@2@AEAUPoint@2@1@Z) 1>sweep_context.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class p2t::Triangle * __cdecl p2t::Triangle::GetNeighbor(int)" (__imp_?GetNeighbor@Triangle@p2t@@QEAAPEAV12@H@Z) 1>sweep_context.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl p2t::Point::~Point(void)" (__imp_??1Point@p2t@@QEAA@XZ) referenced in function "public: void * __cdecl p2t::Point::scalar deleting destructor'(unsigned int)" (??_GPoint@p2t@@QEAAPEAXI@Z) 1>sweep_context.obj : error LNK2019: unresolved external symbol "declspec(dllimport) public: cdecl p2t::Edge::Edge(struct p2t::Point &,struct p2t::Point &)" (imp_??0Edge@p2t@@QEAA@AEAUPoint@1@0@Z) referenced in function "private: void __cdecl p2t::SweepContext::InitEdges(class std::vector<struct p2t::Point ,class std::allocator<struct p2t::Point > > const &)" (?InitEdges@SweepContext@p2t@@AEAAXAEBV?$vector@PEAUPoint@p2t@@V?$allocator@PEAUPoint@p2t@@@std@@@std@@@Z) 1>sweep_context.obj : error LNK2019: unresolved external symbol "declspec(dllimport) public: bool cdecl p2t::Triangle::IsInterior(void)" (imp_?IsInterior@Triangle@p2t@@QEAA_NXZ) referenced in function "public: void __cdecl p2t::SweepContext::MeshClean(class p2t::Triangle &)" (?MeshClean@SweepContext@p2t@@QEAAXAEAVTriangle@2@@Z) 1>sweep_context.obj : error LNK2019: unresolved external symbol "declspec(dllimport) public: void cdecl p2t::Triangle::IsInterior(bool)" (imp_?IsInterior@Triangle@p2t@@QEAAX_N@Z) referenced in function "public: void cdecl p2t::SweepContext::MeshClean(class p2t::Triangle &)" (?MeshClean@SweepContext@p2t@@QEAAXAEAVTriangle@2@@Z) 1>C:\Users\MCX\source\repos\Poly2Tri-Test\x64\Debug\Poly2Tri-Test.exe : fatal error LNK1120: 7 unresolved externals 1>Done building project "Poly2Tri-Test.vcxproj" -- FAILED.`

That's all... I can't use the library for some reason. I'm not very good at building fellow programmers' 3rd-party libraries.

jhasse commented 1 year ago

I would suggest using CMake :)

You'd then link poly2tri like this in your CMakeLists.txt:

add_subdirectory(path/to/poly2tri)

add_executable(your_executable main.cpp)
target_link_libraries(your_executable PRIVATE poly2tri)
mconicx commented 1 year ago

Same thing with CMake. Did I fail to build the library properly, maybe?

jhasse commented 1 year ago

Can you share your CMakeLists.txt with which it fails?

mconicx commented 1 year ago

My apologies. I understood you meant when building this repository. Visual Studio does everything for me, and I got a hold of the lib file just fine without any error. I changed nothing in the settings or cmake files. Just built everything.

As for my project, I avoid using CMake because it is too complicated for me. But, I've linked the lib file properly.

Added include directory where poly2tri.h is and the sweep folder. I can call the class, methods, etc fine.

Solution settings > C++ > Additional library directories > "path where poly2tri.lib is"

Then

Linker > Input > "manually write poly2tri.lib to the list"

Still getting unresolved external symbol errors. Why would CMake make a difference in this case? I would prefer avoiding it as much as possible, if I'm not being too fussy for your time. :)

jhasse commented 1 year ago

As for my project, I avoid using CMake because it is too complicated for me.

Actually it's less complicated than Visual Studio. Errors such as yours often come from the build flags (especially considering the MSVC runtime) being different between the library and the program where it's being linked into.

It's fixable, but more complicated than just using CMake. Visual Studio has native support for it now, btw.