I'm here so I can find a solution for my problem. I know this is too simple, but somehow I can't figure out where's the error in my code!
Here you have it:
AulaData.h
#ifndef AULADATA_H_
#define AULADATA_H_
#include <string>
using std::string;
class AulaData
{
private:
int dia;
public:
AulaData(int dia);
};
#endif
AulaData.cpp
#include "AulaData.h"
AulaData::AulaData(int dia)
{
}
And finally, my Main.cpp:
#include <vector>
#include "AulaData.h"
using namespace std;
int main(int argc, char* argv[])
{
AulaData a(12);
getchar();
return 0;
}
The error I'm getting is the following(something that never happened to me):
1>ConsoleApplication1.obj : error LNK2019: unresolved external symbol
"public: __thiscall AulaData::AulaData(int)" (??0AulaData##QAE#XZ)
referenced in function _main
Although if I define the class constructor without arguments, it'll work.
I'd appreciate a lot if someone could help me! :) I'm trully getting frustrated because all seems ok.
Thanks in advance!
I think that you must provide a default constructor as well if you create one with arguments.
Related
I know similar question is already been made but none of the answers helped me.
I get this error :
MSVCRT.lib(exe_main.obj) : error LNK2001: unresolved external symbol _main
I am using VS17. I created a Wizard Console Application and a Static Lib.
My A.cpp also looks like this
#include <iostream>
#include "A.h"
namespace img{
int main(int argc, char* argv[]{
...
return 0;
}
}
I tried changing the Properties of the Project as many suggested but everything looks fine.
Main needs to be defined in the global namespace as per conversion.
I am having some trouble with the implementation of a constructor and I cannot figure out what is the problem. I have spent a lot of time with this problem: it would be grateful some kind of advice.
The main code is:
#include "stdafx.h"
#include "Rocket.h"
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
Rocket* rocket;
rocket=new Rocket();
//LLA* position=rocket->positionLLA;
return 0;
}
Rocket.h
#pragma once
#include "LLA.h"
class Rocket {
public:
Rocket(); // Default constructor
LLA* positionLLA;
};
Rocket.cpp
#include "stdafx.h"
#include "Rocket.h"
#include <iostream>
using namespace std;
Rocket::Rocket() // Default constructor
{
// Initialise the position
positionLLA=new LLA();
}
The error says:
error LNK2019: unresolved external symbol "public: __thiscall Rocket::Rocket(void)" (??0Rocket##QAE#XZ) referenced in function _main.
I know the error has something to do with not having declared a variable, but I think I have declared all classes and constructors.
PS: I am using Visual Studio 2008 in order to add dependencies.
I am assuming LLA is correctly defined in your .h file
Are you compiling Rocket.cpp into Rocket.o and main.cpp into main.o and then linking the two object files together?
Your error seems to imply that the linker cannot obtain symbol information from Rocket.o, which usually means Rocket.o was not found
Oh, as a detail, since Rocket is using an LLA*, you don't need to include LLA.h in Rocket.h, you can simply forward-declare
class LLA;
You might want to add #ifndef, #define, and #endif to your header files. Having multiple includes of the same thing in different files can lead to complications.
I am getting the two errors when I try to compile my code. I have defined win32 consile application. I have not even yet started coding. My configurations are the following - Linker - subsytem - Console; Linker - Advanced - Entry Point - Blank.
error LNK2019: unresolved external symbol _main referenced in function
___tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals
I don't know what happened. Before everything was working fine but from today it does not. Do you have any idea how I can resolve it that?
My code so far is
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "tbb/blocked_range.h"
#include "tbb/tbb.h"
#include <stdio.h>
#include <math.h>
#include <iostream>
#include "tbb/parallel_for.h"
#include <sstream>
#include <tbb/task_scheduler_init.h>
using namespace std;
#define PI 3.14159265
using namespace tbb;
// Sequential Execution
class Sequential
{
double * m;
double *n;
public:
Sequential(double n[], double m[]): n(n), m(m){}
void Partition()
{
}
int main(int argc, char** argv)
{
//double a = 5;
//double b = 4;
//Sequential g = Sequential(a,b);
return 0;
}
};
Thanks
The main function must be in the global namespace. C++ is not C#/Java where all functions must be inside classes.
I can't seem to fix this LNK2019 Error that I keep getting on visual studio 2013.
I've been looking on stack exchange for a while, but I think my code is fine.
The error is a result of creating a ParkingMeter variable. I'm not sure how to fix this. Any help would be appreciated.
ParkingMeter.h:
#ifndef PARKINGMETER
#define PARKINGMETER
using namespace std;
class ParkingMeter{
private:
int minPurchased;
public:
ParkingMeter(int);
ParkingMeter();
int getMinutes();
};
#endif
ParkingMeter.cpp:
using namespace std;
#include "ParkingMeter.h"
ParkingMeter::ParkingMeter(int minutes)
{
minPurchased = minutes;
}
ParkingMeter::ParkingMeter(){
minPurchased = 0;
}
int ParkingMeter::getMinutes(){ return minPurchased; }
test.cpp:
#include <iostream>
#include "ParkingMeter.h"
using namespace std;
int main()
{
ParkingMeter meter(2);
}
Full error message:
Error 1 error LNK2019: unresolved external symbol "public: __thiscall ParkingMeter::ParkingMeter(int)" (??0ParkingMeter##QAE#H#Z) referenced in function _main C:\Users\Max\Documents\Visual Studio 2013\Projects\Project3\Project3\test.obj
I don't see any problem with this code.
I have removed below code from your ParkingMeter.h and ParkingMeter.cpp. (keep in test.cpp file)
using namespace std;
Edit: It seems you have not added ParkingMeter.cpp in your project. Please right click on your project - > Add -> existing Item -> and provide cpp file. You are good to go!
I am just probing some more advanced coding in C++, so imagine my frustration when I can't solve this:
1>Main.obj : error LNK2019: unresolved external symbol "int __cdecl playerAtk(void)" (? playerAtk##YAHXZ) referenced in function _main
1>C:\Users\Hezekiah Detinc\documents\visual studio 2010\Projects\Custom_1\Debug\Custom_1.exe : fatal error LNK1120: 1 unresolved externals
I had tried searching for an answer here, but the solutions I have found were too specific to be of any use for me.
If anyone can answer; What generally causes this problem? What are some solutions to fixing it?
This is my Main.cpp;
//Custom 1
//Include files that may be used. will cut out unused files in release.
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include "EnemyBaseClass.h"
#include "PlayerBaseClass.h"
using namespace std;
int main()
{
Enemy emy;
Player plr;
emy.enemyAtk();
emy.enemyDef();
emy.enemyHp();
plr.playerAtk();
plr.playerDef();
plr.playerHp();
int playerAtk();
cout << playerAtk();
cout << "You're attacked by a Monster!\n";
system(" pause ");
return 0;
}
If I need to post my headers or the other _.cpp files, let me know.
You declare and use playerAtk as a function (with no implementation, thus the undefined reference)
Change
int playerAtk();
...
cout << playerAtk();
to
int playerAtk;
...
cout << playerAtk;
(You probably want to initialize the variable)
The error is simple: You are using a function which you have declared, but you have not written any definition (Implementation). Check your source (.cpp) files.