I was trying to draw the HalfEdge Data Structure solid with openGL, and I have to subdivision face which may have holes and turn the face to triangles. I use the poly2tri lib. Relate Code is blow.
void Renderer::Poly2Triangles(Face* face)
{
Plane2D plane(face);
std::vector<p2t::Point*> all_points;
std::vector<p2t::Point*> out_points;
std::vector<p2t::Point*> in_points;
//outter loop
Loop* outerLoop = face->fLoops;
while (outerLoop->IsInnerLoop) outerLoop = outerLoop->lNext;
glm::vec3 firstEdge = (outerLoop->lHEdge->destination->Pos).position - (outerLoop->lHEdge->origin->Pos).position;
glm::vec3 secondEdge = (outerLoop->lHEdge->Next->destination->Pos).position - (outerLoop->lHEdge->Next->origin->Pos).position;
glm::vec3 norm = glm::normalize(glm::cross(firstEdge, secondEdge));
HalfEdge* he = outerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
all_points.push_back(point);
out_points.push_back(point);
he = he->Next;
} while (he != outerLoop->lHEdge);
p2t::CDT cdt(std::move(out_points)); //-----------first link error here---------------
//inner loop
Loop* innerLoop = face->fLoops;
do {
if (!(innerLoop->IsInnerLoop)) {
innerLoop = innerLoop->lNext;
continue;
}
HalfEdge* he = innerLoop->lHEdge;
do {
glm::vec2 p = plane.Space3DToPlane2D((he->origin->Pos).position);
p2t::Point* point = new p2t::Point(p.x, p.y);
in_points.push_back(point);
all_points.push_back(point);
he = he->Next;
} while (he != innerLoop->lHEdge);
cdt.AddHole(std::move(in_points));//----------------link error-------------
innerLoop = innerLoop->lNext;
} while (innerLoop != face->fLoops);
cdt.Triangulate();//-----------------------link error------------------------
auto tris = cdt.GetTriangles();//------------------------link error----------------------
for (auto tri : tris) {
Triangle triangle;
for (int i = 0; i < 3; i++) {
auto _p = tri->GetPoint(i);
triangle.vertex[i] = plane.Plane2DToSpace3D(glm::vec2(_p->x, _p->y));
triangle.normal[i] = norm;
}
triangles.push_back(triangle);
}
for (auto p : all_points)
delete p;
}
When I try to run it, it shows five link error:
Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::CDT(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (??0CDT#p2t##QAE#V?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall p2t::CDT::~CDT(void)" (??1CDT#p2t##QAE#XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::AddHole(class std::vector<struct p2t::Point *,class std::allocator<struct p2t::Point *> >)" (?AddHole#CDT#p2t##QAEXV?$vector#PAUPoint#p2t##V?$allocator#PAUPoint#p2t###std###std###Z),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall p2t::CDT::Triangulate(void)" (?Triangulate#CDT#p2t##QAEXXZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
1>Renderer.obj : error LNK2019: 无法解析的外部符号 "public: class std::vector<class p2t::Triangle *,class std::allocator<class p2t::Triangle *> > __thiscall p2t::CDT::GetTriangles(void)" (?GetTriangles#CDT#p2t##QAE?AV?$vector#PAVTriangle#p2t##V?$allocator#PAVTriangle#p2t###std###std##XZ),函数 "private: void __thiscall Renderer::Poly2Triangles(class Face *)" (?Poly2Triangles#Renderer##AAEXPAVFace###Z) 中引用了该符号
just all the p2t::CDT class member was unresolved external symbol: CDT、~CDT、CDT::AddHole、 CDT::Triangulate、CDT::GetTriangles
I use VS2022 build this project, I add the poly2tri header file to the include file path in project properties. the file structure is blow and I just #include "poly2tri.h". it actually pass the compile.
I have no idea what's going on, I want to find errors and correct them. Or I'm happy to know other way to subdivision polygon to triangles.
Related
This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 1 year ago.
I am trying to compile some files related to a server. During compilation I get some errors with unresolved external symbol public: __thiscall CDboTSTAgency::CDboTSTAgency(void), so I read some peoples answers about how to resolve it. Basically, most of the people problems was that they forgot to implement the constructor in the cpp after declaring it. In my case they are implemented but I still get the errors.
See code below:
DboTSTAgency.h
#ifndef _DBO_TSTAGENCY_H_
#define _DBO_TSTAGENCY_H_
#include "DboTSCoreDefine.h"
class CDboTSCompleteQInfo;
class CDboTSTRecv;
class CDboTSTCtrl;
class CDboTSMain;
/**
Trigger agency
*/
class CDboTSTAgency : public CNtlTSAgency
{
NTL_TS_DECLARE_RTTI
// Declarations
public:
typedef std::map<NTL_TS_T_ID, CDboTSTCtrl*> mapdef_TRIGGER_LIST;
// Member variables
protected:
CDboTSMain* m_pParent;
CDboTSTRecv* m_pRecv;
mapdef_TRIGGER_LIST m_defCurTList;
// Constructions and Destructions
public:
CDboTSTAgency();
virtual ~CDboTSTAgency( void );
// Methods
public:
virtual void Update( void );
CDboTSMain* GetParent( void );
void SetParent( CDboTSMain* pParent );
CDboTSTRecv* GetRecv( void );
void SetRecv( CDboTSTRecv* pRecv );
mapdef_TRIGGER_LIST* GetCurTList( void ) { return &m_defCurTList; }
CDboTSTCtrl* FindProgressTrigger( NTL_TS_T_ID tId );
void AttachProgressTrigger( NTL_TS_T_ID tId, CDboTSTCtrl* pCtrl );
void DetachProgressTrigger( NTL_TS_T_ID tId );
// Implementations
protected:
virtual CDboTSTCtrl* MakeTriggerController( CNtlTSTrigger* pTrig );
};
inline CDboTSMain* CDboTSTAgency::GetParent( void )
{
return m_pParent;
}
inline CDboTSTRecv* CDboTSTAgency::GetRecv( void )
{
return m_pRecv;
}
#endif
DboTSTAgency.cpp
#include "precomp_trigger.h"
#include "DboTSTRecv.h"
#include "DboTSTCtrl.h"
#include "DboTSMain.h"
#include "DboTSCtrlFactory.h"
#include "DboTSTAgency.h"
/**
Trigger agency
*/
NTL_TS_IMPLEMENT_RTTI(CDboTSTAgency, CNtlTSAgency)
CDboTSTAgency::CDboTSTAgency(void)
: m_pParent( 0 ),
m_pRecv( 0 )
{
}
CDboTSTAgency::~CDboTSTAgency( void )
{
}
void CDboTSTAgency::Update( void )
{
mapdef_TRIGGER_LIST::iterator itCPQ = m_defCurTList.begin();
for ( ; itCPQ != m_defCurTList.end(); )
{
CDboTSTCtrl* pQCtrl = itCPQ->second;
if ( pQCtrl->IsExitState() )
{
GetParent()->GetControlFactory()->DeleteObj( (CNtlTSControlObject*&)pQCtrl );
itCPQ = m_defCurTList.erase( itCPQ );
}
else
{
pQCtrl->Update();
++itCPQ;
}
}
}
void CDboTSTAgency::SetParent( CDboTSMain* pParent )
{
m_pParent = pParent;
}
void CDboTSTAgency::SetRecv( CDboTSTRecv* pRecv )
{
m_pRecv = pRecv;
}
CDboTSTCtrl* CDboTSTAgency::FindProgressTrigger( NTL_TS_T_ID tId )
{
mapdef_TRIGGER_LIST::iterator it = m_defCurTList.find( tId );
if ( it == m_defCurTList.end() ) return 0;
else return it->second;
}
void CDboTSTAgency::AttachProgressTrigger( NTL_TS_T_ID tId, CDboTSTCtrl* pCtrl )
{
m_defCurTList[tId] = pCtrl;
}
void CDboTSTAgency::DetachProgressTrigger( NTL_TS_T_ID tId )
{
mapdef_TRIGGER_LIST::iterator it = m_defCurTList.find( tId );
if ( it != m_defCurTList.end() ) m_defCurTList.erase( it );
}
CDboTSTCtrl* CDboTSTAgency::MakeTriggerController( CNtlTSTrigger* pTrig )
{
// Trigger controller
CNtlTSControlObject* pCtrlObj = GetParent()->GetControlFactory()->CreateObj( "CDboTSTCtrl" );
if ( !pCtrlObj->IsDerivedClass( "CDboTSTCtrl" ) )
{
CNtlTSLog::Log( "Can not do type cast from CNtlTSControlObject to CDboTSTCtrl. Info[%s]. [%s]", pCtrlObj->GetClassName(), TS_CODE_TRACE() );
m_pParent->GetControlFactory()->DeleteObj( pCtrlObj );
return 0;
}
((CDboTSTCtrl*)pCtrlObj)->SetTrigger( pTrig );
((CDboTSTCtrl*)pCtrlObj)->SetParent( this );
return (CDboTSTCtrl*)pCtrlObj;
}
The error during compilation is:
error LNK2001: unresolved external symbol "public: __thiscall
CDboTSTAgency::CDboTSTAgency(void)" (??0CDboTSTAgency##QAE#XZ)
"unresolved external symbol" is most of the time linker error.
Also in LNK2001 LNK indicates linker .So here linker is unable to find the definition of the function CDboTSTAgency::CDboTSTAgency(void).
Your declaration of constructor is CDboTSTAgency::CDboTSTAgency()
but you are defining constructor for CDboTSTAgency::CDboTSTAgency(void)
Change your code like this and see if it works
DboTSTAgency.h
// Constructions and Destructions
public:
CDboTSTAgency(void );
virtual ~CDboTSTAgency( void );
So I am using TagLib in WinRT Component and trying to get Album arts of mp3 files and then save them to separate files. So far I am using this code:
auto albumartFolder = ApplicationData::Current->LocalFolder;
StorageFile^ destStorageFile = create_task(albumartFolder->CreateFileAsync("\\AlbumArts\\" + destFileName + ".jpg")).get();
TagLib::MPEG::File mpegFile(file->Path->Data());
static const char *IdPicture = "APIC";
TagLib::ID3v2::Tag *id3v2tag = mpegFile.ID3v2Tag();
TagLib::ID3v2::FrameList Frame;
TagLib::ID3v2::AttachedPictureFrame *PicFrame;
void *RetImage = NULL, *SrcImage;
unsigned long Size;
FILE *jpegFile;
jpegFile = fopen((char*)destStorageFile->Path->Data(), "wb");
if (id3v2tag)
{
Frame = id3v2tag->frameListMap()[IdPicture];
if (!Frame.isEmpty())
{
for (TagLib::ID3v2::FrameList::ConstIterator it = Frame.begin(); it != Frame.end(); ++it)
{
PicFrame = (TagLib::ID3v2::AttachedPictureFrame *)(*it);
if ( PicFrame->type() ==
TagLib::ID3v2::AttachedPictureFrame::FrontCover)
{
Size = PicFrame->picture().size();
SrcImage = malloc(Size);
if (SrcImage)
{
memcpy(SrcImage, PicFrame->picture().data(), Size);
fwrite(SrcImage, Size, 1, jpegFile);
fclose(jpegFile);
free(SrcImage);
}
}
}
}
}
This code should work without a bug I know but here are the exceptions I am recieving:
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::FileName::FileName(wchar_t const *)" (??0FileName#TagLib##QAE#PB_W#Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: __thiscall TagLib::MPEG::File::File(class TagLib::FileName,bool,enum TagLib::AudioProperties::ReadStyle)" (??0File#MPEG#TagLib##QAE#VFileName#2#_NW4ReadStyle#AudioProperties#2##Z) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
1>LibraryModule.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall TagLib::MPEG::File::~File(void)" (??1File#MPEG#TagLib##UAE#XZ) referenced in function "public: bool __thiscall <lambda_88d334404ef137d46dbb027b26f435b8>::operator()(void)const " (??R<lambda_88d334404ef137d46dbb027b26f435b8>##QBE_NXZ)
Any help regarding this would be appreciated very much!
Edit:
So, this is marked as duplicate but I still cannot fix the problem. How do I link Taglib correctly? I installed the Nuget package, was I wrong to do so?
I am looking to use the C++ neural network library "OpenNN".
http://www.opennn.net/
I am relatively new to C++ project management and I believe my issue is caused by this.
I have cloned the openNN repo.
I copied the relevant folders form the repo across in to the folder that i created to contain all OpenNN project i plan to make.
I then made a c++ console application in visual studio, in this folder that i am using for testing.
so dir structure is :
OpenNN (where i plan to keep all openNN projects)
---eigen
---opennn
---tinyxml2
---OpenNNTest (my test project folder)
I have done some testing with the Vector and Matrix classes that are part of OpenNN and that all worked fine.
The below code however returns the following two external symbol errors:
Error LNK2019 unresolved external symbol "public: __thiscall OpenNN::NeuralNetwork::NeuralNetwork(class OpenNN::Vector<unsigned int> const &)" (??0NeuralNetwork#OpenNN##QAE#ABV?$Vector#I#1##Z) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
Error LNK2019 unresolved external symbol "public: virtual __thiscall
OpenNN::NeuralNetwork::~NeuralNetwork(void)" (??1NeuralNetwork#OpenNN##UAE#XZ) referenced in function "void __cdecl NNTest(void)" (?NNTest##YAXXZ) OpenNNTest D:\Projects\OpenNN\OpenNNTest\OpenNNTest\OpenNNTest.obj 1
interestingly, if I change:
OpenNN::NeuralNetwork nn(architecture);
to
OpenNN::NeuralNetwork nn();
No issues, as if it finds the default constructor but not the overloaded one?
The code I am using is as follows:
#include "stdafx.h"
#include "../../opennn/opennn.h"
using namespace OpenNN;
using std::cout;
using std::endl;
void NNTest()
{
OpenNN::Vector<unsigned> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
//Vector<double> inputs(2);
//inputs[0] = 0.5;
//inputs[1] = 0.1;
//Vector<double> outputs = nn.calculate_outputs(inputs);
//cout << outputs << endl;
//nn.save("neural_network.xml");
}
int main()
{
NNTest();
getchar();
return 0;
}
You need to change the type unsigned to size_t:
OpenNN::Vector<size_t> architecture(5);
architecture[0] = 2;
architecture[1] = 2;
architecture[2] = 4;
architecture[3] = 3;
architecture[4] = 1;
OpenNN::NeuralNetwork nn(architecture);
I hope that helps.
I'm using C++ and Visual Studio Professional 2013 to write a wrapper for the Windows API (to make it easier to read). When I try to compile the solution, I get two linker errors related to the Intersect function in the wRectangle class. I commented out the function to see what the cause of the problem was, and the solution compiled and ran fine. From this, I determined that it was because the return type was an object of the class name (i.e. The Intersect function in the wRectangle class returns a wRectangle object). Moving the implementation of the Intersect function to its prototype in Rectangle.h fixed the issue, but I would prefer to keep the implementation in Rectangle.cpp. Any way to solve this?
Relevant files, most of the comments have been removed since they serve no relevance:
Rectangle.h:
#include <Windows.h>
#include "Typedefs.h"
#include "Window.h"
namespace windows_API_Wrapper
{
#ifndef RECTANGLE_H
#define RECTANGLE_H
class wRectangle
{
public:
wRectangle();
wRectangle(uInt32 xMin, uInt32 xMax, uInt32 yMin, uInt32 yMax);
void operator=(wRectangle &assignment);
void operator=(Window assignment);
boolean operator!=(wRectangle nonComparable);
wRectangle Intersect(wRectangle source1, wRectangle source2);
void Normalize();
private:
rectangle rect; //A wRectangle structure (typedef of a RECT strucure), for internal use only
};
#endif //RECTANGLE_H
}
Rectangle.cpp:
#include "Rectangle.h"
using namespace windows_API_Wrapper;
wRectangle::wRectangle()
{
this->rect.left = 0;
this->rect.top = 0;
this->rect.right = 0;
this->rect.bottom = 0;
}
void wRectangle::operator=(wRectangle &assignment)
{
this->rect.left = assignment.rect.left;
this->rect.top = assignment.rect.top;
this->rect.right = assignment.rect.right;
this->rect.bottom = assignment.rect.bottom;
}
void wRectangle::operator=(Window assignment)
{
if (GetClientRect(assignment.Get(), &this->rect) == 0)
MessageBox(null, "Failed to assign window dimensions to wRectangle!", "ERROR", MB_ICONEXCLAMATION);
}
boolean wRectangle::operator==(wRectangle comparable)
{
return EqualRect(&this->rect, &comparable.rect);
}
boolean wRectangle::operator!=(wRectangle nonComparable)
{
return !EqualRect(&this->rect, &nonComparable.rect);
}
wRectangle wRectangle::Intersect(wRectangle source1, wRectangle source2)
{
wRectangle destination;
IntersectRect(&destination.rect, &source1.rect, &source2.rect);
return destination;
}
void wRectangle::Normalize()
{
if (this->rect.top > this->rect.bottom)
{
uInt32 temp = this->rect.top;
this->rect.top = this->rect.bottom;
this->rect.bottom = temp;
}
if (this->rect.left > this->rect.right)
{
uInt32 temp = this->rect.left;
this->rect.left = this->rect.right;
this->rect.right = temp;
}
}
Error 1:
error LNK2019: unresolved external symbol "public: __thiscall
windows_API_Wrapper::wRectangle::wRectangle(class windows_API_Wrapper::wRectangle const &)" (??
0wRectangle#windows_API_Wrapper##QAE#ABV01##Z) referenced in function "public: class
windows_API_Wrapper::wRectangle __thiscall windows_API_Wrapper::wRectangle::Intersect(class
windows_API_Wrapper::wRectangle,class windows_API_Wrapper::wRectangle)" (?
Intersect#wRectangle#windows_API_Wrapper##QAE?AV12#V12#0#Z)
File: G:\Visual Studio Projects\Windows API Wrapper\Windows API Wrapper\Rectangle.obj
Project: Windows API Wrapper
Error 2:
error LNK1120: 1 unresolved externals
File: G:\Visual Studio Projects\Windows API Wrapper\Debug\Windows API Wrapper.exe
Project: Windows API Wrapper
This is because you have not defined
wRectangle(uInt32 xMin, uInt32 xMax, uInt32 yMin, uInt32 yMax);
I got this when compiling my DLL project:
Error 1 error LNK2019: unresolved external symbol "public: unsigned char * __thiscall CDetour::GetThisPtr(void)" (?GetThisPtr#CDetour##QAEPAEXZ) referenced in function "void __stdcall zCharacter_OnDamagedHook(struct ZObject *,struct D3DXVECTOR3,int,int,float,float,int)" (?zCharacter_OnDamagedHook##YGXPAUZObject##UD3DXVECTOR3##HHMMH#Z) C:\Users\Andrés\Documents\Visual Studio 2010\Projects\2k7_A-H\2k7_A-H\AntiLead.obj 2k7_A-H
Where I'm using "zCharacter_OnDamagedHook" is here:
void __stdcall zCharacter_OnDamagedHook(ZObject* pAttacker, D3DXVECTOR3 srcPos, int damageType, int weaponType, float fDamage, float fPiercingRatio, int nMeleeType) {
zCharacter_OnDamagedDetour.Ret(true);
std::string channelName = ZGameClient::GetInstance()->CurrentChannel;
ZCharacter* victim = (ZCharacter*)zCharacter_OnDamagedDetour.GetThisPtr();
ZCharacter* attacker = (ZCharacter*)pAttacker;
ZCharacter* me = (ZCharacter*)ZGame::GetInstance()->pMyCharacter;
if ((channelName.find("[No-Lead]") == std::string::npos) && (channelName.find("[No-Lead]") == std::string::npos)) {
ZCharacterManager* charm = ZCharacterManager::GetInstance();
if (((attacker == me) && (victim != me)) && (damageType != 5) && (damageType != 1) && (damageType != 2)) {
zCharacter_OnDamagedDetour.Ret(false);
MUID uidVictim;
for (unsigned int i = 0; i < muidList.size(); ++i) {
if (charm->Find(muidList[i]) == victim) {
uidVictim = muidList[i];
break;
}
}
MCommand* pCmd = MCommand::Create(0xD3D9);
pCmd->AddParameter(new MCommandParameterInt(uidVictim.lowId));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.x));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.y));
pCmd->AddParameter(new MCommandParameterFloat(srcPos.z));
pCmd->AddParameter(new MCommandParameterInt(damageType));
pCmd->AddParameter(new MCommandParameterInt(weaponType));
pCmd->AddParameter(new MCommandParameterFloat(fDamage));
pCmd->AddParameter(new MCommandParameterFloat(fPiercingRatio));
pCmd->AddParameter(new MCommandParameterInt(nMeleeType));
MCommand::Post(pCmd);
}
I really don't know what I'm doing wrong, also I hadn't got this error before so I hope someone could help me, thranks in advance.
Your CDetour class has declared a member function GetThisPtr but none of your source (.cpp) files has provided a definition.
Since you didn't show any of that code it's impossible to comment further.