I get the error below when i call new TerrainClass() from the main, tried for hours to fix it, help please.
error LNK2019: unresolved external symbol "public: __thiscall TerrainClass::TerrainClass(void)" (??0TerrainClass##QAE#XZ) referenced in function "void __cdecl init(void)" (?init##YAXXZ)
GLDrawObject.h
#pragma once
class GLDrawObject
{
};
Terrain.cpp
#pragma once
TerrainClass::TerrainClass() : GLDrawObject()
{
}
Terrain.h
#pragma once
#include "GLDrawObject.h"
class TerrainClass : public GLDrawObject
{
public:
TerrainClass();
};
Firstly, your Terrain.cpp should be as follows:
#include "Terrain.h"
TerrainClass::TerrainClass() : GLDrawObject()
{
}
Secondly, you are getting a linker error, not a compiler error; once compiled, you need to link Terrain.o with the rest of your object files.
Related
recently I'm working on a UE5 project that uses filesystem to read and render a .obj file directly from a given path, but my code generates 58 LNK2019 errors around the read file process after compiling it. I have tried many possible solutions like #include everything that I may need. However, the LNK2019 still exists.
Then I comment everything out of my file and I found that even if my .cpp and .h are empty but have #include <filesystem> it causes 5 LNK2019 errors. When I delete this file and create another one, then include it, it happens again. I didn't found what the compiler version of UE5 working set is, but it's said to be C++17
Basically this is my .cpp
#include "OBJMeshComponent.h"
//yes literally just one line.
and this is my .h
#pragma once
#include "CoreMinimal.h"
#include "ProceduralMeshComponent.h"
#include <fstream>
#include <iostream>
#include <filesystem> // this causes 5 LNK2019
#include "OBJMeshComponent.generated.h"
UCLASS()
class PROJECT_API UOBJMeshComponent : public UProceduralMeshComponent
{
GENERATED_BODY()
//as you can see it is empty
};
for the build output file:
OBJProceduralMeshComponent.gen.cpp.obj : error LNK2019: 无法解析的外部符号 "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ),函数 "protected: void __cdecl std::time_get<char,class std::istreambuf_iterator<char,struct std::char_traits<char> > >::_Getvals<wchar_t>(wchar_t,class std::_Locinfo const &)" (??$_Getvals#_W#?$time_get#DV?$istreambuf_iterator#DU?$char_traits#D#std###std###std##IEAAX_WAEBV_Locinfo#1##Z) 中引用了该符号
OBJProceduralMeshComponent.cpp.obj : error LNK2001: 无法解析的外部符号 "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc#std##YAXXZ)
OBJProceduralMeshComponent.gen.cpp.obj : error LNK2001: 无法解析的外部符号 _Mbrtowc
OBJProceduralMeshComponent.cpp.obj : error LNK2001: 无法解析的外部符号 _Mbrtowc
OBJProceduralMeshComponent.gen.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: struct _Cvtvec __cdecl std::_Locinfo::_Getcvt(void)const " (__imp_?_Getcvt#_Locinfo#std##QEBA?AU_Cvtvec##XZ),函数 "protected: void __cdecl std::time_get<char,class std::istreambuf_iterator<char,struct std::char_traits<char> > >::_Getvals<wchar_t>(wchar_t,class std::_Locinfo const &)" (??$_Getvals#_W#?$time_get#DV?$istreambuf_iterator#DU?$char_traits#D#std###std###std##IEAAX_WAEBV_Locinfo#1##Z) 中引用了该符号
OBJProceduralMeshComponent.cpp.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: struct _Cvtvec __cdecl std::_Locinfo::_Getcvt(void)const " (__imp_?_Getcvt#_Locinfo#std##QEBA?AU_Cvtvec##XZ)
OBJProceduralMeshComponent.gen.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " (__imp_?_W_Getdays#_Locinfo#std##QEBAPEBGXZ),函数 "protected: void __cdecl std::time_get<char,class std::istreambuf_iterator<char,struct std::char_traits<char> > >::_Getvals<wchar_t>(wchar_t,class std::_Locinfo const &)" (??$_Getvals#_W#?$time_get#DV?$istreambuf_iterator#DU?$char_traits#D#std###std###std##IEAAX_WAEBV_Locinfo#1##Z) 中引用了该符号
OBJProceduralMeshComponent.cpp.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: unsigned short const * __cdecl std::_Locinfo::_W_Getdays(void)const " (__imp_?_W_Getdays#_Locinfo#std##QEBAPEBGXZ)
OBJProceduralMeshComponent.gen.cpp.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " (__imp_?_W_Getmonths#_Locinfo#std##QEBAPEBGXZ),函数 "protected: void __cdecl std::time_get<char,class std::istreambuf_iterator<char,struct std::char_traits<char> > >::_Getvals<wchar_t>(wchar_t,class std::_Locinfo const &)" (??$_Getvals#_W#?$time_get#DV?$istreambuf_iterator#DU?$char_traits#D#std###std###std##IEAAX_WAEBV_Locinfo#1##Z) 中引用了该符号
OBJProceduralMeshComponent.cpp.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: unsigned short const * __cdecl std::_Locinfo::_W_Getmonths(void)const " (__imp_?_W_Getmonths#_Locinfo#std##QEBAPEBGXZ)
C:\Users\liuyi\Documents\Unreal Projects\Assignment2\Binaries\Win64\UnrealEditor-Assignment2.patch_0.exe : fatal error LNK1120: 5 个无法解析的外部命令
I am trying to implement a PointArray class derived from a template. Here is what my hpp file for PointArray looks like:
#ifndef POINTARRAY_H
#define POINTARRAY_H
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "Array.hpp"
using namespace Abhishek::CAD;
using namespace Abhishek::CONTAINERS;
namespace Abhishek
{
namespace CONTAINERS
{
class PointArray : public Array<Point>
{
public:
PointArray();//Default constrcutor.
PointArray(int size);//Constructor with size argument.
PointArray(const PointArray& arr);//Copy constructor.
~PointArray();//Destructor.
double Length() const;//Length function.
};
}
}
#endif
My cpp looks like this :
#include <iostream>
#include <sstream>
#include <stdio.h>
#include "PointArray.hpp"
using namespace Abhishek::CAD;
using namespace Abhishek::CONTAINERS;
namespace Abhishek
{
namespace CONTAINERS
{
//Default constructor.
PointArray::PointArray(): Array<Point>()
{
cout<<"Point arr default cons"<<endl;
}
//Constructor with size argument.
PointArray::PointArray(int size) : Array<Point>(size)
{
}
//Copy constructor.
PointArray::PointArray(const PointArray& arr) : Array<Point>(arr)
{
}
//destrcutor.
PointArray::~PointArray()
{
}
}
}
I get the LNK error :
error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(void)" (??0?$Array#VPoint#CAD#Abhishek###CONTAINERS#Abhishek##QAE#XZ) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(void)" (??0PointArray#CONTAINERS#Abhishek##QAE#XZ)
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(int)" (??0?$Array#VPoint#CAD#Abhishek###CONTAINERS#Abhishek##QAE#H#Z) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(int)" (??0PointArray#CONTAINERS#Abhishek##QAE#H#Z)
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::Array<class Abhishek::CAD::Point>(class Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point> const &)" (??0?$Array#VPoint#CAD#Abhishek###CONTAINERS#Abhishek##QAE#ABV012##Z) referenced in function "public: __thiscall Abhishek::CONTAINERS::PointArray::PointArray(class Abhishek::CONTAINERS::PointArray const &)" (??0PointArray#CONTAINERS#Abhishek##QAE#ABV012##Z)
1>PointArray.obj : error LNK2019: unresolved external symbol "public: __thiscall Abhishek::CONTAINERS::Array<class Abhishek::CAD::Point>::~Array<class Abhishek::CAD::Point>(void)" (??1?$Array#VPoint#CAD#Abhishek###CONTAINERS#Abhishek##QAE#XZ) referenced in function __unwindfunclet$??0PointArray#CONTAINERS#Abhishek##QAE#XZ$0
1>C:\Users\Rambo\Documents\Level 6\Section 4.2b\Exercise 3\Debug\Exercise 3.exe : fatal error LNK1120: 4 unresolved externals
I dont understand why this could be happening. I included all the relevant header files and CPP files. If anyone can help I will really appreciate it.
You forgot to post the most relevant header: the one that declares the class template that causes the error. Almost certainly, that header declares the default constructor of the Array template:
Array();
but doesn't define it; either there is no definition, or you have a definition in a source file.
In either case, you'll get an error since templates must be defined in any translation unit that uses them. This means that you'll need to define the constructor (and any other member functions) in the header, to include them wherever they are used.
If that's not the problem, then please post the header so we can investigate further.
I have c++ classes that are needed to import in python.
For that I am using SWIG. Below is the swig interface
example.i
/* File: example.i */
%module example
%{
#include "Item.h"
#include "GradedDouble.h"
#include "GradedComplex.h"
%}
%include <std_string.i>
%include <std_complex.i>
%include "Item.h"
%include "GradedDouble.h"
%include "GradedComplex.h"
%template(Int) Item<int>;
%template(Complex) Item<std::complex<double> >;
And for creating wrapper class and python module I am executing following command in windows XP environment
c:\>swig -c++ -python -nodefaultctor example.i
c:\>python setup.py build_ext --inplace
After executing second command I am getting the following error :
*C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild /EXPORT:init_example build\temp.win32-2.6\Release\example_wrap.obj "/OUT:C:\Documents and Settings\swig_example.pyd" /IMPLIB:build\temp.win32-2.6\Release\_example.lib /MANIFESTFILE:build\temp.win32-2.6\Release\_example.pyd.manifest
Creating library build\temp.win32-2.6\Release\_example.lib and object build\temp.win32-2.6\Release\_example.exp
example_wrap.obj : error LNK2019: unresolved external symbol "public: __thiscall GradedDouble::~GradedDouble(void)" (??1GradedDouble##QAE#XZ) referenced in function __wrap_delete_GradedDouble
example_wrap.obj : error LNK2019: unresolved external symbol "public: __thiscall GradedComplex::~GradedComplex(void)" (??1GradedComplex##QAE#XZ) referenced in function __wrap_delete_GradedComplex
example_wrap.obj : error LNK2019: unresolved external symbol "public: __thiscall GradedDouble::GradedDouble(int,double *)" (??0GradedDouble##QAE#HPAN#Z) referenced in function __wrap_new_GradedDouble
example_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall GradedDouble::avg(double *)" (?avg#GradedDouble##QAEXPAN#Z) referenced in function __wrap_GradedDouble_avg
example_wrap.obj : error LNK2019: unresolved external symbol "public: __thiscall GradedComplex::GradedComplex(int,double *)" (??0GradedComplex##QAE#HPAN#Z) referenced in function __wrap_new_GradedComplex
example_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall GradedComplex::avg(double *)" (?avg#GradedComplex##QAEXPAN#Z) referenced in function __wrap_GradedComplex_avg
example_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall GradedComplex::push(class Item<class std::complex<double> >)" (?push#GradedComplex##QAEXV?$Item#V?$complex#N#std#####Z) referenced in function __wrap_GradedComplex_push
example_wrap.obj : error LNK2019: unresolved external symbol "public: void __thiscall GradedDouble::push(class Item<double>)" (?push#GradedDouble##QAEXV?$Item#N###Z) referenced in function __wrap_GradedDouble_push
C:\Documents and Settings\swig_example.pyd : fatal error LNK1120: 8 unresolved externals
error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\link.exe"'failed with exit status 1120*
It seems there are issue in creating interface file of swig (example.i)
I need help for creating interface file. Following are the header files
GradedComplex.h
#ifndef __GRADEDCOMPLEX_H__
#define __GRADEDCOMPLEX_H__
#include <complex>
#include <set>
#include <vector>
#include "Item.h"
class GradedComplex
{
public:
typedef std::complex<double> dcomplex;
typedef Item<dcomplex> item_type;
typedef ItemComparator<dcomplex> comparator;
typedef std::set<item_type, comparator> grade_type;
private:
int n_;
std::vector<grade_type *> grade_;
std::vector<double> thre_;
public:
GradedComplex(int n, double *thre);
~GradedComplex();
void push(item_type item);
void avg(double *buf);
};
#endif
Graded Double.h
#ifndef __GRADEDDOUBLE_H__
#define __GRADEDDOUBLE_H__
#include <set>
#include <vector>
#include "Item.h"
class GradedDouble
{
public:
typedef Item<double> item_type;
typedef ItemComparator<double> comparator;
typedef std::set<item_type, comparator> grade_type;
private:
int n_;
std::vector<grade_type *> grade_;
std::vector<double> thre_;
public:
GradedDouble(int n, double *thre);
~GradedDouble();
void push(item_type item);
void avg(double *buf);
};
#endif
Please help me for creating correct SWIG interface file.
It looks like the link operation is missing the definitions for your GradedDouble and GradedComplex classes.
You have to provide these definitions to the linker, either in the form of object files, or in the form of a library.
I don't know enough about SWIG on Windows (only use it on Linux) to be able to help further on how to solve this.
I'm creating a QLabel subclass which adds the DoubleClickEvent to it. I have created the following, but I'm getting some strange linker errors, maybe someone can point out what I've done wrong?
//Header
#ifndef IMAGE_LABEL_H
#define IMAGE_LABEL_H
#include <QLabel>
#include <QMouseEvent>
class image_label : public QLabel
{
Q_OBJECT
public:
image_label(QWidget* parent = 0);
~image_label();
signals:
void doubleClicked();
protected:
void mouseDoubleClickEvent(QMouseEvent * e);
};
#endif
//CPP
#include "image_label.h"
#include <QMouseEvent>
image_label::image_label(QWidget* parent) : QLabel(parent)
{
}
image_label::~image_label()
{
}
void image_label::mouseDoubleClickEvent(QMouseEvent* e)
{
if (e->button() == Qt::LeftButton)
{
emit doubleClicked();
QLabel::mouseDoubleClickEvent(e);
}
}
I get the following linker errors when I compile:
image_label.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall image_label::metaObject(void)const " (?metaObject#image_label##UBEPBUQMetaObject##XZ)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall image_label::qt_metacast(char const *)" (?qt_metacast#image_label##UAEPAXPBD#Z)
image_label.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall image_label::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall#image_label##UAEHW4Call#QMetaObject##HPAPAX#Z)
image_label.obj : error LNK2019: unresolved external symbol "protected: void __thiscall image_label::doubleClicked(void)" (?doubleClicked#image_label##IAEXXZ) referenced in function "protected: virtual void __thiscall image_label::mouseDoubleClickEvent(class QMouseEvent *)" (?mouseDoubleClickEvent#image_label##MAEXPAVQMouseEvent###Z)
Can anybody help why I get these errors?
You must run the MOC preprocessor on the file image_label.h. This generates a file moc_image_label.cppthat you must include in the build. The error message indicates that you have not done this. (The symbols image_label::metaObject etc. that are mentioned in the error message are defined in moc_image_label.cpp.)
Code
#include <OOLua/oolua.h>
class foo
{
public:
int bar();
};
OOLUA_CLASS_NO_BASES(foo)//class has no bases
OOLUA_NO_TYPEDEFS
OOLUA_MEM_FUNC_0(int,bar)
OOLUA_CLASS_END
void test()
{
OOLUA::Script s;
s.register_class<foo>();
}
Compiler output
1>main.obj : error LNK2001: unresolved external symbol "public: static struct OOLUA::Proxy_class<class foo>::Reg_type_const * OOLUA::Proxy_class<class foo>::class_methods_const" (?class_methods_const#?$Proxy_class#Vfoo###OOLUA##2PAUReg_type_const#12#A)
1>main.obj : error LNK2001: unresolved external symbol "public: static struct OOLUA::Proxy_class<class foo>::Reg_type * OOLUA::Proxy_class<class foo>::class_methods" (?class_methods#?$Proxy_class#Vfoo###OOLUA##2PAUReg_type#12#A)
1>main.obj : error LNK2001: unresolved external symbol "public: static char const * const OOLUA::Proxy_class<class foo>::class_name" (?class_name#?$Proxy_class#Vfoo###OOLUA##2QBDB)
1>main.obj : error LNK2001: unresolved external symbol "public: static char const * const OOLUA::Proxy_class<class foo>::class_name_const" (?class_name_const#?$Proxy_class#Vfoo###OOLUA##2QBDB)
1>main.obj : error LNK2001: unresolved external symbol "public: static int const OOLUA::Proxy_class<class foo>::name_size" (?name_size#?$Proxy_class#Vfoo###OOLUA##2HB)
Using
Visual Studio 2008
OOLua 1.2.1
(OOLua .lib has been built and linked to)
(OOLua solution via premake 3 with test.unit and profile projects removed)
(OOLua obtained via SVN -> trunk | Jan 3rd)
Links
http://code.google.com/p/oolua/
OOLua compile errors
Question
How can it be fixed?
Solution
class foo
{
public:
int bar()
{
return 0;
}
};
OOLUA_CLASS_NO_BASES(foo)//class has no bases
OOLUA_NO_TYPEDEFS
OOLUA_MEM_FUNC_0(int,bar)
OOLUA_CLASS_END
EXPORT_OOLUA_FUNCTIONS_1_NON_CONST(foo /*name of class*/
,bar)/*function being exposed*/
EXPORT_OOLUA_FUNCTIONS_0_CONST(foo)
void test()
{
OOLUA::Script s;
s.register_class<foo>();
}
http://code.google.com/p/oolua/wiki/CheatSheet#Has_a_member_function_which_takes_no_parameters
Then in a source file expose the class
telling the framework that the
instance has a function of interest
yet no constant member functions, also
providing the name it will be
identified by in Lua code(foo).
EXPORT_OOLUA_FUNCTIONS_1_NON_CONST(foo /*name of class*/
,bar)/*function being exposed*/
EXPORT_OOLUA_FUNCTIONS_0_CONST(foo)