I am getting an error in Visual Studio when compiling my program.
Error LNK2019 unresolved external symbol "public: __cdecl
Grid::Grid(void)" (??0Grid##QEAA#XZ) referenced in function
main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1
Error LNK2019 unresolved external symbol "public: __thiscall
Grid::~Grid(void)" (??1Grid##QAE#XZ) referenced in function
_main Grid C:\Users\Ryan\Desktop\Dev\Grid\Grid\main.obj 1
This project works fine at my university but not on my own computer and I am not sure what is wrong.
My main.cpp:
#include <iostream>
#include "Grid.h"
using namespace std;
int main(int args, char **argv)
{
Grid grid;
// grid.LoadGrid("Grid1.txt");
// grid.SaveGrid("OutGrid.txt");
system("pause");
}
And my header file:
#pragma once
class Grid
{
public:
Grid();
~Grid();
void LoadGrid(const char filename[]);
void SaveGrid(const char filename[]);
private:
int m_grid[9][9];
};
Any help at all is appreciated, thanks.
Issue resolved from advise given on [error LNK2019: unresolved external symbol "public: __thiscall : constructor issue
"First in the library project do rightclick->properties, then under the tab General, Configuration Type should be Static library (.lib)."
Thanks everyone for your answers.
As per my understanding your grid class constructor and destractor implementation are missing. You should check your .cpp file, implemention like this
Grid(){}
~ Grid(){}
Related
I'm getting these error messages
2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall CEngine::CEngine(void)" (??0CEngine##QAE#XZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::SetWindowSize(int,int,char const *,int)" (?SetWindowSize#CEngine##QAEXHHPBDH#Z) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::Begin(void)" (?Begin#CEngine##QAEXXZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayWidth(void)" (?GetDisplayWidth#CEngine##QAEHXZ) referenced in function _WinMain#16
2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayHeight(void)" (?GetDisplayHeight#CEngine##QAEHXZ) referenced in function _WinMain#16
2>C:\Users\ethan\Desktop\C++ Projects\delveenginetest\Debug\delveenginetest.exe : fatal error LNK1120: 5 unresolved externals
This is my solution:
Solution 'delveenginetest' (2 projects)
DelveEngine
Include
delve.h
Engine.h
SetupSDL.h
stdafx.h
Engine.cpp
Main.cpp
SetupSDL.cpp
This is the code for Engine.h
#pragma once
#include "SetupSDL.h"
class CEngine
{
public:
CEngine(void);
~CEngine(void);
void SetWindowSize(int winW, int winH, const char* GameName, int windowMode);
void Begin(void);
int GetDisplayWidth(void);
int GetDisplayHeight(void);
private:
int deskW;
int deskH;
bool playing;
CSetupSDL* sdl_setup;
};
Code for Engine.cpp
#include "Include/stdafx.h"
#include "Include/Engine.h"
CEngine::CEngine(void)
{
playing = true;
deskW = GetSystemMetrics(SM_CXSCREEN);
deskH = GetSystemMetrics(SM_CYSCREEN);
}
CEngine::~CEngine(void)
{
}
void CEngine::SetWindowSize(int winW, int winH, const char* GameName, int windowMode)
{
// set up SDL for use
sdl_setup = new CSetupSDL(winW, winH, GameName, windowMode);
}
void CEngine::Begin(void)
{
while (playing && sdl_setup->GetMainEvent()->type != SDL_QUIT)
{
sdl_setup->Begin();
sdl_setup->End();
}
playing = false;
}
int CEngine::GetDisplayWidth(void){ return deskW; }
int CEngine::GetDisplayHeight(void){ return deskH; }
The DelveEngine project builds successfully, whereas the delveenginetest project fails.
What's wrong? I've looked everywhere for a reason, can't find one that suits me.
Despite the fact you're not providing all the sufficient information for a correct diagnosis of your problems, I'll try to share what I could imagine that might be the reasons for the linker errors:
I suppose the project delveenginetest you mention is meant to set up unit tests for the classes from the DelveEngine project.
Since you have a Main.cpp in your DelveEngine project, I'd guess it's simply build as an executable (successfully).
Your delveenginetest needs to link to the classes provided from the DelveEngine project, but that's actually not possible, since the .exe from DelveEngine can't be used for linking, you'll need a library to import it to another executable (the unit testing framework).
I'd recommend to separate out your classes/source files from DelveEngine project to make up a static or shared library, that can be linked from an application and the test framework simultaneously from within a single VS solution:
Solution 'DelveEngine' (3 projects)
DelveEngineLib (project [.lib/.dll])
Include
delve.h
Engine.h
SetupSDL.h
Engine.cpp
SetupSDL.cpp
DelveEngine (project [.exe])
Main.cpp
delveenginetest (project [.exe])
Main.cpp (TestFramework main definition)
Since I'm not very versed with it I don't know actually, if VS 2013 supports to setup projects consuming virtual resources (think of links to sources in the actual build environment), but this could be an alternative how to setup application and unit tests without need of an extra library.
I have a visual c++ console project named "C_test".
Another project is called "dll_project" which is dll project.
in "C_test" project, I have set the location of additional include directory for "dll_project".
I have these simple codes.
in "C_test" project's main.cpp.
#include "SampleClass.h"
int main()
{
SampleClass *_parser = new SampleClass();
return 0;
}
And in "dll_project" SampleClass.h and SampleClass.cpp.
SampleClass.h
#pragma once
class SampleClass
{
public:
SampleClass(void);
~SampleClass(void);
};
SampleClass.cpp
#include "SampleClass.h"
SampleClass::SampleClass(void)
{
}
SampleClass::~SampleClass(void)
{
}
When I try to debug or build, I get this error.
error LNK2019: unresolved external symbol "public: __thiscall SampleClass::SampleClass(void)" (??0SampleClass##QAE#XZ) referenced in function _main C:\C_test\main.obj C_test
What have I done wrong?
Hi i'm getting the following errors:
Error 9 error LNK1120: 2 unresolved externals
Error 8 error LNK2019: unresolved external symbol "public: virtual __thiscall physics::~physics(void)" (??1physics##UAE#XZ) referenced in function "public: virtual void * __thiscall physics::`scalar deleting destructor'(unsigned int)" (??_Gphysics##UAEPAXI#Z)
Error 7 error LNK2019: unresolved external symbol "public: virtual __thiscall student::~student(void)" (??1student##UAE#XZ) referenced in function __unwindfunclet$??0physics##QAE#XZ$0
which occur using the following code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class student{
protected:
string fName,sName;
int id;
vector<string> cname;
vector<int> cmark;
public:
virtual ~student();
virtual void addCourse(string name, int mark)=0;
};
class physics : public student{
public:
physics(){//Initialize default values
fName="blank";
sName="blank";
id=0;
cname.push_back("none");
cmark.push_back(0);
};
~physics();
void addCourse(string name, int mark){
if(cname.size()==1){//override default value for a size of 1
cname[0]=name;
cmark[0]=mark;
}
else{
cname.push_back(name);
cmark.push_back(mark);
}
}
};
The above compiles fine but when i try to initialize an object in main() by using:
int main(){
//Database Storage
vector<student*> DB;
DB.push_back(new physics);
}
That's when i get the errors (removing the push_back line fixes it but i need this for my program). What am i doing wrong?
Turns out adding braces to the end of the destructors fixed it. What difference does that make? (from the comments)
The difference is that in one case you have a declaration which lacks a definition; in the second case you provide a (empty) definition inline.
Trying to invoke a function that is declared but not defined (as in the first case) result in an unresolved reference error raised by the linker - after all, what should it do when a function invocation is found for a function whose implementation is not available?
I'm trying to build a solution with 2 projects and get these error messages:
ColliderTest.obj : error LNK2028: undefined token (0A000080) "public: __thiscall Rect::Rect(int)" (??0Rect##$$FQAE#XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction##$$FYAXXZ)
ColliderTest.obj : error LNK2019: unresolved external symbol "public: __thiscall Rect::Rect(int)" (??0Rect##$$FQAE#XZ) referenced in function "void __cdecl myFunction(void)" (?myFunction##$$FYAXXZ)
The code:
In the project "Collider" I have these files:
Collider.h
#pragma once
class Rect{
int x;
int y;
unsigned int w;
unsigned int h;
public:
Rect(int x);
};
Collider.cpp
#include "Collider.h"
Rect::Rect(int x){
this->x = x;
}
The project "ColliderTest" has a reference to the project Collider, and this file:
ColliderTest.cpp
#include "../app/Collider.h"
void myFunction();
void myFunction(){
Rect rect(4);
}
Also, each project has a main.cpp file with an empty main() function, to avoid the complains of the compiller about the entry point.
Both projects have a main function?
That means you are building two executable. Executables typically do not export functions.
You need one executable and one class library (dll).
BTW: If you have an empty main function, how will you know if your program ran?
When I try and build my project I get the following errors:
1>Assignment1CoreTest.obj : error LNK2019: unresolved external symbol "struct point * __cdecl findLongPaths(struct point *,double)" (?findLongPaths##YAPAUpoint##PAU1#N#Z) referenced in function "public: void __thiscall Geometry_CoreUnitTest::test_method(void)" (?test_method#Geometry_CoreUnitTest##QAEXXZ)
1>Assignment1CoreTest.obj : error LNK2019: unresolved external symbol "double __cdecl calculateLineLength(struct point *)" (?calculateLineLength##YANPAUpoint###Z) referenced in function "public: void __thiscall Geometry_CoreUnitTest::test_method(void)" (?test_method#Geometry_CoreUnitTest##QAEXXZ)
1>C:\Users\user\documents\visual studio 2010\Projects\Assignment1\Debug\Assignment1.exe : fatal error LNK1120: 2 unresolved externals
I've been trying to work out why for the last hour or so and have made absolutely no progress so I was wondering if anyone might be able to point me in the right direction. Obviously I'm doing something stupid but I can't work out what.
This is my AssignmentOneCoreTest.cpp:
#define BOOST_TEST_MODULE Test_Assignment1
#include <boost/test/unit_test.hpp>
#include "geometry.h"
BOOST_AUTO_TEST_CASE(Geometry_CoreUnitTest) {
point p[3] = {{0,0}, {0,3}, {0,1, true}};
point longest[2] = {{0,1}, {0,3,true}};
BOOST_CHECK_EQUAL(calculateLineLength(p), 5);
point *longest_calculated = findLongPaths(p, 1.1);
BOOST_CHECK_EQUAL(longest_calculated[1].y, longest[1].y);
delete longest_calculated;
}
Geometry.cpp:
#include "geometry.h"
#include <iostream>
using namespace std;
double calculateLineLength(point *points)
{
...
}
point *findLongPaths(point *points, double threshold_distance)
{
...
}
and Geometry.h:
#ifndef GEOMETRY_H
#define GEOMETRY_H
typedef struct {
int x;
int y;
bool end;
} point;
double calculateLineLength(point *points);
point *findLongPaths(point *points, double threshold_distance);
#endif
I'm totally stumped and starting to get kinda frustrated, what am I overlooking?
you are getting linker error.
Most probably you are not generating the object code for Geometry.cpp
this would work for now:
create an empty project;
copy the header files in the headerfiles folder
copy the cpp files in the cpp files folder
then build the project;
this will build your Geometry.cpp program as well.