LNK2001 error on atoi and stoi function with proper includes added - c++

I have this project that throws LNK2001 error on using atoi while proper includes added:
#... //other headers
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <iostream>
BOOL main(int argc, char* argv[]){
ShowNumber(atoi(argv[1]));
return TRUE;
}
Error is: LNK2001: Unresolved external symbol _atoi
I do know that LNK error happens while a header confusion occurs. But i don't think that headers are the problem here. Is there anything in the project configuration or header conflict that may cause this to break? Also i get 15 other LNK2001 on using std::stoi.
Visual studio 2017 with 2015 or 2017 toolset.

Related

LNK2019 when using Lua from NuGet package [duplicate]

I use Lua ver 5.2.3 with visual studio 2010 , when i compile code below
#include "stdafx.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include <stdlib.h>
#include <stdio.h>
void main()
{
lua_State *luaState = luaL_newstate();
}
I got error
error LNK2019: unresolved external symbol "struct lua_State * __cdecl luaL_newstate(void)" (?luaL_newstate##YAPAUlua_State##XZ) referenced in function _wmain
Could you please give me any advice about this .
Thank !!!
This is a result of C++ "name mangling". See how there are strange characters in this term:
?luaL_newstate##YAPAUlua_State##XZ
You have choices:
Change the file extension of this file to .c instead of .cpp, so that it runs through the C compiler instead of the C++ compiler (caveat: depending on compiler)
or
Add extern "C" around the includes like this:
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
or
#include "lua.hpp"
In the last case, that header is included with the 5.2 release. It does what I wrote in option 2 for you.

error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup and Error 2 error LNK1120: 1 unresolved externals

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.

error LNK2019: unresolved external symbol newbie needs tip

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.

Reading from std::cin produces Linker error

I have a rather unusual problem. I am trying to do this:
char *content = new char[10000];
std::cin.read(content, 10000);
And I get the following linker error (weird because the code was compiling fine a few weeks ago, and it hasn't been modified):
Error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::read(char *,__int64)" (__imp_?read#?$basic_istream#DU?$char_traits#D#std###std##QAEAAV12#PAD_J#Z) main.obj
I verified that I have all the required dependencies linked in the Project Properties, verified that I have /MT set, and the like. The project was compiling fine just a few weeks ago-- the only thing I have done between then and now is update VS2012. Here are my includes.
#include <stdlib.h>
#ifdef _WIN32
#include <process.h>
#else
#include <unistd.h>
extern char ** environ;
#endif
#include "fcgio.h"
#include "fcgi_config.h"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>
It appears that after updating Visual Studio 2012, the project (somehow) became non-functional. Copying the exact same code over to a new project has fixed the problem.

Unresolved external symbol in c++

#include <iostream>
#include <cstdlib>
using std::cout;
using std::endl;
using std::rand;
int man(){
int t=rand();
cout<<t<<endl;
return 0;
}
here is code for generate random number in c++ and i have mistake
1>c:\users\david\documents\visual studio 2010\Projects\random_function\Debug\random_function.exe : fatal error LNK1120: 1 unresolved externals
please help
Change man() to main().
Me, I think I'd change "man" to "main" and see what happens...