Error lnk2001 unresolved external symbol winmain 16

C++ Documentation. Contribute to MicrosoftDocs/cpp-docs development by creating an account on GitHub.
description title ms.date f1_keywords helpviewer_keywords ms.assetid

Learn more about: Linker Tools Error LNK2001

Linker Tools Error LNK2001

10/22/2021

LNK2001

LNK2001

dc1cf267-c984-486c-abd2-fd07c799f7ef

unresolved external symbol «symbol«

The compiled code makes a reference or call to symbol. The symbol isn’t defined in any libraries or object files searched by the linker.

This error message is followed by fatal error LNK1120. To fix error LNK1120, first fix all LNK2001 and LNK2019 errors.

There are many ways to get LNK2001 errors. All of them involve a reference to a function or variable that the linker can’t resolve, or find a definition for. The compiler can identify when your code doesn’t declare a symbol, but not when it doesn’t define one. That’s because the definition may be in a different source file or library. If your code refers to a symbol, but it’s never defined, the linker generates an error.

What is an unresolved external symbol?

A symbol is the internal name for a function or global variable. It’s the form of the name used or defined in a compiled object file or library. A global variable is defined in the object file where storage is allocated for it. A function is defined in the object file where the compiled code for the function body is placed. An external symbol is one referenced in one object file, but defined in a different library or object file. An exported symbol is one that’s made publicly available by the object file or library that defines it.

To create an application or DLL, every symbol used must have a definition. The linker must resolve, or find the matching definition for, every external symbol referenced by each object file. The linker generates an error when it can’t resolve an external symbol. It means the linker couldn’t find a matching exported symbol definition in any of the linked files.

Compilation and link issues

This error can occur:

  • When the project is missing a reference to a library (.LIB) or object (.OBJ) file. To fix this issue, add a reference to the required library or object file to your project. For more information, see lib Files as linker input.

  • When the project has a reference to a library (.LIB) or object (.OBJ) file that in turn requires symbols from another library. It may happen even if you don’t call functions that cause the dependency. To fix this issue, add a reference to the other library to your project. For more information, see Understanding the classical model for linking: Taking symbols along for the ride.

  • If you use the /NODEFAULTLIB or /Zl options. When you specify these options, libraries that contain required code aren’t linked into the project unless you’ve explicitly included them. To fix this issue, explicitly include all the libraries you use on the link command line. If you see many missing CRT or Standard Library function names when you use these options, explicitly include the CRT and Standard Library DLLs or library files in the link.

  • If you compile using the /clr option. There may be a missing reference to .cctor. For more information on how to fix this issue, see Initialization of mixed assemblies.

  • If you link to the release mode libraries when building a debug version of an application. Similarly, if you use options /MTd or /MDd or define _DEBUG and then link to the release libraries, you should expect many potential unresolved externals, among other problems. Linking a release mode build with the debug libraries also causes similar problems. To fix this issue, make sure you use the debug libraries in your debug builds, and retail libraries in your retail builds.

  • If your code refers to a symbol from one library version, but you link a different version of the library. Generally, you can’t mix object files or libraries that are built for different versions of the compiler. The libraries that ship in one version may contain symbols that can’t be found in the libraries included with other versions. To fix this issue, build all the object files and libraries with the same version of the compiler before linking them together. For more information, see C++ binary compatibility between Visual Studio versions.

  • If library paths are out of date. The Tools > Options > Projects > VC++ Directories dialog, under the Library files selection, allows you to change the library search order. The Linker folder in the project’s Property Pages dialog box may also contain paths that could be out of date.

  • When a new Windows SDK is installed (perhaps to a different location). The library search order must be updated to point to the new location. Normally, you should put the path to new SDK include and lib directories in front of the default Visual C++ location. Also, a project containing embedded paths may still point to old paths that are valid, but out of date. Update the paths for new functionality added by the new version that’s installed to a different location.

  • If you build at the command line, and have created your own environment variables. Verify that the paths to tools, libraries, and header files go to a consistent version. For more information, see Use the MSVC toolset from the command line.

Coding issues

This error can be caused by:

  • Mismatched case in your source code or module-definition (.def) file. For example, if you name a variable var1 in one C++ source file and try to access it as VAR1 in another, this error is generated. To fix this issue, use consistently spelled and cased names.

  • A project that uses function inlining. It can occur when you define the functions as inline in a source file, rather than in a header file. Inlined functions can’t be seen outside the source file that defines them. To fix this issue, define the inlined functions in the headers where they’re declared.

  • Calling a C function from a C++ program without using an extern "C" declaration for the C function. The compiler uses different internal symbol naming conventions for C and C++ code. The internal symbol name is what the linker looks for when resolving symbols. To fix this issue, use an extern "C" wrapper around all declarations of C functions used in your C++ code, which causes the compiler to use the C internal naming convention for those symbols. Compiler options /Tp and /Tc cause the compiler to compile files as C++ or C, respectively, no matter what the filename extension is. These options can cause internal function names different from what you expect.

  • An attempt to reference functions or data that don’t have external linkage. In C++, inline functions and const data have internal linkage unless explicitly specified as extern. To fix this issue, use explicit extern declarations on symbols referred to outside the defining source file.

  • A missing function body or variable definition. This error is common when you declare, but don’t define, variables, functions, or classes in your code. The compiler only needs a function prototype or extern variable declaration to generate an object file without error, but the linker can’t resolve a call to the function or a reference to the variable because there’s no function code or variable space reserved. To fix this issue, make sure to define every referenced function and variable in a source file or library you link.

  • A function call that uses return and parameter types or calling conventions that don’t match the ones in the function definition. In C++ object files, Name decoration encodes the calling convention, class or namespace scope, and return and parameter types of a function. The encoded string becomes part of the final decorated function name. This name is used by the linker to resolve, or match, calls to the function from other object files. To fix this issue, make sure the function declaration, definition, and calls all use the same scopes, types, and calling conventions.

  • C++ code you call, when you include a function prototype in a class definition, but don’t include the implementation of the function. To fix this issue, be sure to provide a definition for all class members you call.

  • An attempt to call a pure virtual function from an abstract base class. A pure virtual function has no base class implementation. To fix this issue, make sure all called virtual functions are implemented.

  • Trying to use a variable declared within a function (a local variable) outside the scope of that function. To fix this issue, remove the reference to the variable that isn’t in scope, or move the variable to a higher scope.

  • When you build a Release version of an ATL project, producing a message that CRT startup code is required. To fix this issue, do one of the following,

    • Remove _ATL_MIN_CRT from the list of preprocessor defines to allow CRT startup code to be included. For more information, see General property page (Project).

    • If possible, remove calls to CRT functions that require CRT startup code. Instead, use their Win32 equivalents. For example, use lstrcmp instead of strcmp. Known functions that require CRT startup code are some of the string and floating point functions.

Consistency issues

There’s currently no standard for C++ name decoration between compiler vendors, or even between different versions of the same compiler. Object files compiled with different compilers may not use the same naming scheme. Linking them can cause error LNK2001.

Mixing inline and non-inline compile options on different modules can cause LNK2001. If a C++ library is created with function inlining turned on (/Ob1 or /Ob2) but the corresponding header file describing the functions has inlining turned off (no inline keyword), this error occurs. To fix this issue, define the functions inline in the header file you include in other source files.

If you use the #pragma inline_depth compiler directive, make sure you’ve set a value of 2 or greater, and make sure you also use the /Ob1 or /Ob2 compiler option.

This error can occur if you omit the LINK option /NOENTRY when you create a resource-only DLL. To fix this issue, add the /NOENTRY option to the link command.

This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain. To fix this issue, make sure you match the options to the project type. For more information on these options and entry points, see the /SUBSYSTEM and /ENTRY linker options.

Exported .def file symbol issues

This error occurs when an export listed in a .def file isn’t found. It could be because the export doesn’t exist, is spelled incorrectly, or uses C++ decorated names. A .def file doesn’t take decorated names. To fix this issue, remove unneeded exports, and use extern "C" declarations for exported symbols.

Use the decorated name to find the error

The C++ compiler and linker use Name Decoration, also known as name-mangling. Name decoration encodes extra information about the type of a variable in its symbol name. The symbol name for a function encodes its return type, parameter types, scope, and calling convention. This decorated name is the symbol name the linker searches for to resolve external symbols.

A link error can result if the declaration of a function or variable doesn’t exactly match the definition of the function or variable. That’s because any difference becomes part of the symbol name to match. The error can happen even if the same header file is used in both the calling code and the defining code. One way it may occur is if you compile the source files by using different compiler flags. For example, if your code is compiled to use the __vectorcall calling convention, but you link to a library that expects clients to call it using the default __cdecl or __fastcall calling convention. In this case, the symbols don’t match because the calling conventions are different.

To help you find the cause, the error message shows you two versions of the name. It displays both the «friendly name,» the name used in source code, and the decorated name (in parentheses). You don’t need to know how to interpret the decorated name. You can still search for and compare it with other decorated names. Command-line tools can help to find and compare the expected symbol name and the actual symbol name:

  • The /EXPORTS and /SYMBOLS options of the DUMPBIN command-line tool are useful here. They can help you discover which symbols are defined in your .dll and object or library files. You can use the symbols list to verify that the exported decorated names match the decorated names the linker searches for.

  • In some cases, the linker can only report the decorated name for a symbol. You can use the UNDNAME command-line tool to get the undecorated form of a decorated name.

Additional resources

For more information, see the Stack Overflow question «What is an undefined reference/unresolved external symbol error and how do I fix it?».

WikiLeaks

0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

1

03.03.2014, 17:06. Показов 3732. Ответов 22

Метки нет (Все метки)


Помогите разобрать в ошибке.

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/link.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream.h>
int Add (int x, int y)
{
    cout << "In Add(), received " << x << " and " << y << " n ";
    return (x+y);
}
 
int main ()
{
    cout << " I'm in main()! n";
    int a, b, c;
    cout << " Enter two numbers: ";
    cin >> a;
    cin >> b;
    cout << " nCalling Add()n";
    c=Add(a,b);
    cout << " nBack in main(). n";
    cout << "c was ste to " << c;
    cout << " nExiting...  n n";
    return 0;
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



27 / 22 / 13

Регистрация: 31.07.2013

Сообщений: 121

03.03.2014, 17:12

2

у меня не выбило ошибку



0



Модератор

Эксперт функциональных языков программированияЭксперт Python

33878 / 18905 / 3981

Регистрация: 12.02.2012

Сообщений: 31,694

Записей в блоге: 13

03.03.2014, 17:13

3

Такое впечатление, что компилятор установлен «криво»



0



0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

03.03.2014, 17:20

 [ТС]

4

petyahohlov,
Какой средой пользуешься?



0



1 / 1 / 2

Регистрация: 07.10.2013

Сообщений: 170

03.03.2014, 17:28

5

WikiLeaks, а ты какой средой пользуешься?



0



0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

03.03.2014, 17:39

 [ТС]

6

yurets17,
microsoft visual c++ 6.0



0



yurets17

1 / 1 / 2

Регистрация: 07.10.2013

Сообщений: 170

03.03.2014, 17:44

7

WikiLeaks, тогда извини не подскажу, никогда не работал)
у меня например в Qt не компилирует, пока не поменяю

C++
1
#include <iostream.h>

на

C++
1
2
#include <iostream>
using namespace std;



0



16495 / 8988 / 2205

Регистрация: 30.01.2014

Сообщений: 15,611

03.03.2014, 17:47

8

WikiLeaks, у тебя наверное твой исходник (c main) в дерево проекта не добавлен.



0



THE—MASTER

Заблокирован

03.03.2014, 17:57

9

ты используешь стороннюю библиотеку, рассчитанную на винду, а сам создал консольный проект, делай виндовый проект с функцией WinMain



0



Эксперт С++

4978 / 3085 / 456

Регистрация: 10.11.2010

Сообщений: 11,164

Записей в блоге: 10

03.03.2014, 18:00

10

Проблема в том, что ты создал в VS проект «оконное приложение», а компилируешь «консольное».



1



WikiLeaks

0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

03.03.2014, 18:12

 [ТС]

11

castaway,
сделал как вы сказали.
Результат:

C++
1
c:program files (x86)ewwwmsdev98myprojects221221.cpp(23) : fatal error C1010: unexpected end of file while looking for precompiled header directive



0



THE—MASTER

Заблокирован

03.03.2014, 18:13

12

Цитата
Сообщение от WikiLeaks
Посмотреть сообщение

castaway,
сделал как вы сказали.
Результат:

отключи использование прекомпайл хэдэров, тебе ж пишут.
свойства проекта C/C++ -> Precomplie Headers



0



1 / 1 / 2

Регистрация: 07.10.2013

Сообщений: 170

03.03.2014, 18:16

13

WikiLeaks, попробуй подключить #include «stdafx.h»



0



0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

03.03.2014, 18:27

 [ТС]

14

THE—MASTER,
Отключил.

LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/221.exe : fatal error LNK1120: 1 unresolved externals



0



1 / 1 / 2

Регистрация: 07.10.2013

Сообщений: 170

03.03.2014, 18:29

15

Цитата
Сообщение от WikiLeaks
Посмотреть сообщение

Отключил

Попробуй вернуть обратно и подключить #include «stdafx.h»



0



5493 / 4888 / 831

Регистрация: 04.06.2011

Сообщений: 13,587

03.03.2014, 18:33

16

Цитата
Сообщение от WikiLeaks
Посмотреть сообщение

сделал как вы сказали.

И что сделали?

Добавлено через 27 секунд

Цитата
Сообщение от yurets17
Посмотреть сообщение

Попробуй вернуть обратно и подключить #include «stdafx.h»

Не нужно, тут опять не тот проект.

Добавлено через 1 минуту
Создайте пустой проект: Общие — Пустой проект, добавьте в него файл .cpp, вставьте в него свой код.



0



yurets17

1 / 1 / 2

Регистрация: 07.10.2013

Сообщений: 170

03.03.2014, 18:37

17

Цитата
Сообщение от alsav22
Посмотреть сообщение

Создайте пустой проект: Общие — Пустой проект, добавьте в него файл .cpp, вставьте в него свой код.

а эту строчку не надо менять?

C++
1
#include <iostream.h>



0



5493 / 4888 / 831

Регистрация: 04.06.2011

Сообщений: 13,587

03.03.2014, 18:45

18

Цитата
Сообщение от yurets17
Посмотреть сообщение

а эту строчку не надо менять?

Если компилятор на неё заругается, тогда.

Добавлено через 1 минуту
6-ю студию не знаю.



0



0 / 0 / 0

Регистрация: 02.03.2014

Сообщений: 8

03.03.2014, 18:48

 [ТС]

19

Посоветуйте нормальную студию. А то я замучился с совместимостью 6.0 и win 8.1



0



The following code compiles on VS Express Edition 2008, yet I get the following errors when trying to debug/release:

1>Linking...
1>MSVCRT.lib(crtexew.obj) : error LNK2001: unresolved external symbol _WinMain@16
1>E:Documents and SettingsAdministratorDesktopProyecto 2 gràficastestingReleasetesting.exe : fatal error LNK1120: 1 unresolved externals

is it because it’s unable to link a library? How can I solve this?

#include <windows.h>   // use as needed for your system

#include <gl/Gl.h>
#include <gl/glut.h>
#include <iostream>
#include <fstream>

using namespace std;

//**************Global Data
char ifileName[30];
char oFileName[30];
fstream inFile;
fstream outFile;

//************ Data structure 
struct GLfloatPoint
{ GLfloat x,y;
};

const int MAX = 100;
class GLfloatPointArray
{
public:
  int num;
  GLfloatPoint pt[MAX];
};

//***************** subprograms
typedef GLfloat colorType[3];
// subprogram used to draw the control points separately
void drawDot (GLfloat x, GLfloat y, GLfloat r, GLfloat g, GLfloat b)
{ glColor3f(r,g,b);
  glBegin (GL_POINTS);
      glVertex2f (x,y);
  glEnd();
}
// Drawing subprogram - this will draw the curve from a set of points
void drawFloatPolyLine (GLfloatPointArray P, colorType c)
{ glColor3fv (c);
  glBegin(GL_LINE_STRIP);
   for (int i=0; i < P.num; i++)
     glVertex2f (P.pt[i].x,P.pt[i].y);
  glEnd();
}

//******************** myInit 
 void myInit(void)
 {
    glClearColor(1.0,1.0,1.0,0.0);  // set white background color
    glColor3f (0.0f,0.0f,0.0f);    //default color
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
    gluOrtho2D(0.0, 640.0, 0.0, 480.0);
    // get data files
    cout << "Enter the input file name: ";
    cin >> ifileName;
    inFile.open (ifileName,ios::in);
    if (inFile.fail())
      return;
    // if want to see points for debugging add output
    // cout << "Enter the output file name: ";
    // cin >> oFileName;
    // outFile.open (oFileName,ios::out);
    // if (outFile.fail())
    //   return;
}

//***************** BEZIER Curve subprograms
// Read the control points 
void readControlPoints (GLfloatPointArray &P)
{
  inFile >> P.num;
  for (int j = 0; j < P.num; j++)
    inFile >> P.pt[j].x >> P.pt[j].y;
}
// output control points to a text file - if you want to see the 
// computations
void printPointArray (GLfloatPointArray P)
{
  outFile << "Size: " << P.num << endl << "Points:" << endl;
  for (int j = 0; j < P.num; j++)
    outFile << "(" << P.pt[j].x << "," << P.pt[j].y << ")" << endl;
}

const int MAXCONTPTS = 100;
int c[MAXCONTPTS];   // the binomial coefficients
//helper routines - compute the coefficient
void ComputeCoeff (int n)
{ int j,k;
  for (k=0;k<=n;k++)
  { //compute n! / (k!*(n-k)!)
    c[k] = 1;
    for (j = n;j>=k+1;j--)
      c[k] *=j;
    for (j = n-k;j>=2;j--)
      c[k] /= j;
  }
}
// compute the blending value
float BlendingValue (int n, int k, float t)
{ int j;
  float bv;
  // compute  c[k]*t^k * (1-t)^(n-k)
  bv = c[k];
  for (j=1; j<=k;j++)
    bv *= t;
  for (j = 1;j<=n-k;j++)
    bv *= (1-t);
  return bv;
}

// compute one point on the Bezier curve - fixed value of t
void ComputePoint (float t, int n, GLfloatPoint & p, 
                   GLfloatPointArray ctrlPts)
{ int k;
  float b;
  p.x = 0.0;
  p.y = 0.0;
  for (k = 0; k<=n;k++)
  {  b = BlendingValue (n,k,t);
     p.x += ctrlPts.pt[k].x*b;
     p.y  += ctrlPts.pt[k].y*b;
  }
}
// compute the array of Bezier points - drawing done separately
void Bezier ( GLfloatPointArray controlPts, int numInter, 
              GLfloatPointArray & curve)
{ // there are numContPts+1 control points and numInter t values to evaluate the curve
  int k;
  float t;
  ComputeCoeff (controlPts.num-1);
  curve.num = numInter+1;
  for (k=0; k<=numInter; k++)
  { t = (float) k / (float) numInter;
    ComputePoint (t, controlPts.num-1,curve.pt[k],controlPts);
  }
}

//************************ myDisplay 
void myDisplay(void)
{  
   int numbCurves;
   GLfloatPointArray ControlPts,BezCurve;
   colorType C = {0.0f,1.0f,0.0f};

   glClear(GL_COLOR_BUFFER_BIT);     // clear the screen 

   inFile >> numbCurves;
   for (int i = 0; i < numbCurves; i++)
   { 
     // read control points and draw them in red big points
     readControlPoints (ControlPts);
     glPointSize (4.0);
     for (int j = 0; j < ControlPts.num; j++)
       drawDot (ControlPts.pt[j].x,ControlPts.pt[j].y,1,0,0);
     glPointSize (1.0);
     // Compute the Bezier curve points and draw
     Bezier (ControlPts,50,BezCurve);
       // draw the Bezier curve
     drawFloatPolyLine (BezCurve,C);
     glFlush ();
   }
}

//**************************** main
void main(int argc, char** argv)
{
    glutInit(&argc, argv);          // initialize the toolkit
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
    glutInitWindowSize(640,480);     // set window size
    glutInitWindowPosition(100, 150); // set window position on screen
    glutCreateWindow("Bezier Curve drawing"); // open the screen window
    glutDisplayFunc(myDisplay);     // register redraw function
    myInit();                   
    glutMainLoop();              // go into a perpetual loop
}

ive been working on my project for a while and its been working fine… i havent runned it in release mode for a few days… and today when i tried to compile it in release mode i get the following error..

error LNK2001: unresolved external symbol _WinMain@16

why?! it is a windows application

and it works fine in debug mode

[Edited by — Dragon_Strike on March 30, 2008 8:23:27 AM]

Hello Dragon_Strike,

I guess you are seeing this error because the project has become a little confused about the about whether you are building a console application or a windows application (_WinMain@16 is the entry point for a console application).

I would try the suggestions on the following link: http://www.cryer.co.uk/brian/mswinswdev/msdev_lnk2001ueswm.htm which shows how to check/ change the entry point in MSVC.

Cheers,

Tom

Assuming VC205 (Other versions will be similar): Go to project settings (Alt+F7) -> Configuration Properties -> Linker -> System, and change «Subsystem» to «Windows (/SUBSYSTEM:WINDOWS)».

I suspect that following the above link will have its own problems, since your app will still be being built as a console app.

thx but that didnt help…

i put the entry point in Linker/Advanced to wWinMainCRTStartup … no differance

Quote:Original post by Evil Steve
Assuming VC205 (Other versions will be similar): Go to project settings (Alt+F7) -> Configuration Properties -> Linker -> System, and change «Subsystem» to «Windows (/SUBSYSTEM:WINDOWS)».

I suspect that following the above link will have its own problems, since your app will still be being built as a console app.

it already had that setting… havent changed anything there…

id like to point out that it did work in release mode a few days ago..

EDIT:

could it have something to do with precompiled headers? its the only setting ive been changing the last few days

What does your WinMain() declaration look like?

Demo1.cpp

#include "Demo1.hpp"#include "Application/Win32Exception.hpp"int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){														try													{													  return Demo1().Run();								}													catch(const drone::application::win32::Exception& e)		{													}													catch(const std::exception& e)								{													}													catch(...)											{													::MessageBox(0, TEXT("Unknown Exception"), 0, 0);		}													return 0;										} // APIENTRY

EDIT:: im using VS 2008

What if you rename _tWinMain to WinMain? That’s what the linker is expecting after all…

error C2731: ‘WinMain’ : function cannot be overloaded

It seems like you somehow have inconsistent UNICODE defines in your project; the linker is expecting a non-Unicode version of WinMain() and you’re giving it a Unicode version. If you change the tWinMain() function to WinMain() make sure that the third parameter is a LPSTR, not a LPTSTR.

  • Remove From My Forums
  • Question

  • Hello all,

    I hope I’m posting in the right place.

    I have searched the net and found numerous similar problems but I cannot get a single on to work.

    First of all I have done some c++ programming in VS2005 before but not at this level so I am kind of out of the water here.

    I am running a Vista x64 Ultimate system with Windows Vista Platfrom SDK, DirectX SDK (June 2007) and VS2005 Professional

    I have added all the Include files and Lib files under

    Tools->Options->Projects and Solutions->VC++ Directories

    What I’m trying to compile is skeleton code given to me by a group member. He has a lot more knowledge in DirectX so he created these stubs or skeleton if you will. I’m taking a computer gaming programing course this semester.

    Since I’m the only one running Vista and the x64 bit version he cannot help me.

    I am way over my head here and I don’t know what to do.
    I will switch to an Windows XP x86 soon because I need to get into
    the coding but I would prefer to sit on my main computer which is the Vista x64
    computer.

    Thanks for any help Smile

    Here under are the linking errors I get when I try to build the project.

    Code Snippet

    —— Build started: Project: MAIN — Game, Configuration: Debug Win32 ——
    Linking…
    Searching libraries
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86d3d9.lib:
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86dxerr.lib:
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86d3dx9.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86kernel32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86user32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86gdi32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86winspool.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86comdlg32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86advapi32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86shell32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86ole32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86oleaut32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86uuid.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86odbc32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86odbccp32.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 8VClibmsvcprtd.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 8VClibMSVCRTD.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 8VClibOLDNAMES.lib:
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86d3d9.lib:
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86dxerr.lib:
    Searching C:Program Files (x86)Microsoft DirectX SDK (June 2007)Libx86d3dx9.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86kernel32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86user32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86gdi32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86winspool.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86comdlg32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86advapi32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86shell32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86ole32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86oleaut32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86uuid.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86odbc32.lib:
    Searching C:Program FilesMicrosoft SDKsWindowsv6.0Libx86odbccp32.lib:
    Searching C:Program Files (x86)Microsoft Visual Studio 8VClibmsvcprtd.lib:
    Finished searching libraries
    kernel.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExA@48 referenced in function «public: __thiscall game::Window::Window(char const *,char const *,long (__stdcall*)(struct HWND__ *,unsigned int,unsigned int,long))» (??0Window@game@@QAE@PBD0P6GJPAUHWND__@@IIJ@Z@Z)
    kernel.obj : error LNK2019: unresolved external symbol __imp__RegisterClassExA@4 referenced in function «public: __thiscall game::Window::Window(char const *,char const *,long (__stdcall*)(struct HWND__ *,unsigned int,unsigned int,long))» (??0Window@game@@QAE@PBD0P6GJPAUHWND__@@IIJ@Z@Z)
    kernel.obj : error LNK2019: unresolved external symbol __imp__GetModuleHandleA@4 referenced in function «public: __thiscall game::Window::Window(char const *,char const *,long (__stdcall*)(struct HWND__ *,unsigned int,unsigned int,long))» (??0Window@game@@QAE@PBD0P6GJPAUHWND__@@IIJ@Z@Z)
    kernel.obj : error LNK2019: unresolved external symbol __imp__UnregisterClassA@8 referenced in function «public: __thiscall game::Window::~Window(void)» (??1Window@game@@QAE@XZ)
    kernel.obj : error LNK2019: unresolved external symbol __imp__UpdateWindow@4 referenced in function «public: void __thiscall game::Window::showWindow(void)» (?showWindow@Window@game@@QAEXXZ)
    kernel.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function «public: void __thiscall game::Window::showWindow(void)» (?showWindow@Window@game@@QAEXXZ)
    kernel.obj : error LNK2019: unresolved external symbol __imp__SetWindowPos@28 referenced in function «public: bool __thiscall game::Direct3D9::setWindowed(void)» (?setWindowed@Direct3D9@game@@QAE_NXZ)
    kernel.obj : error LNK2019: unresolved external symbol __imp__SetWindowLongA@12 referenced in function «public: bool __thiscall game::Direct3D9::setWindowed(void)» (?setWindowed@Direct3D9@game@@QAE_NXZ)
    main.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcA@16 referenced in function «long __stdcall MsgProc(struct HWND__ *,unsigned int,unsigned int,long)» (?MsgProc@@YGJPAUHWND__@@IIJ@Z)
    main.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function «long __stdcall MsgProc(struct HWND__ *,unsigned int,unsigned int,long)» (?MsgProc@@YGJPAUHWND__@@IIJ@Z)
    main.obj : error LNK2019: unresolved external symbol __imp__MessageBoxA@16 referenced in function __catch$_WinMain@16$0
    dxerr.lib(dxerr.obj) : error LNK2001: unresolved external symbol __imp__MessageBoxA@16
    main.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageA@4 referenced in function _WinMain@16
    main.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16
    main.obj : error LNK2019: unresolved external symbol __imp__PeekMessageA@20 referenced in function _WinMain@16
    dxerr.lib(dxerr.obj) : error LNK2019: unresolved external symbol __imp__DebugBreak@0 referenced in function _DXTraceW@20
    MSVCRTD.lib(error.obj) : error LNK2001: unresolved external symbol __imp__DebugBreak@0
    dxerr.lib(dxerr.obj) : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _DXTraceW@20
    dxerr.lib(dxerr.obj) : error LNK2019: unresolved external symbol __imp__GetForegroundWindow@0 referenced in function _DXTraceW@20
    dxerr.lib(dxerr.obj) : error LNK2019: unresolved external symbol __imp__OutputDebugStringW@4 referenced in function _DXTraceW@20
    dxerr.lib(dxerr.obj) : error LNK2019: unresolved external symbol __imp__OutputDebugStringA@4 referenced in function _DXTraceA@20
    MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol __imp__InterlockedExchange@8 referenced in function ___tmainCRTStartup
    MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol __imp__Sleep@4 referenced in function ___tmainCRTStartup
    MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol __imp__InterlockedCompareExchange@12 referenced in function ___tmainCRTStartup
    MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol __imp__GetStartupInfoA@4 referenced in function ___tmainCRTStartup
    MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__TerminateProcess@8 referenced in function ___report_gsfailure
    MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentProcess@0 referenced in function ___report_gsfailure
    MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__UnhandledExceptionFilter@4 referenced in function ___report_gsfailure
    MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__SetUnhandledExceptionFilter@4 referenced in function ___report_gsfailure
    MSVCRTD.lib(unhandld.obj) : error LNK2001: unresolved external symbol __imp__SetUnhandledExceptionFilter@4
    MSVCRTD.lib(gs_report.obj) : error LNK2019: unresolved external symbol __imp__IsDebuggerPresent@0 referenced in function ___report_gsfailure
    MSVCRTD.lib(error.obj) : error LNK2001: unresolved external symbol __imp__IsDebuggerPresent@0
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__RaiseException@16 referenced in function «int __cdecl DebuggerProbe(unsigned long)» (?DebuggerProbe@@YAHK@Z)
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__WideCharToMultiByte@32 referenced in function «void __cdecl failwithmessage(void *,int,int,char const *)» (?failwithmessage@@YAXPAXHHPBD@Z)
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__MultiByteToWideChar@24 referenced in function «void __cdecl failwithmessage(void *,int,int,char const *)» (?failwithmessage@@YAXPAXHHPBD@Z)
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__lstrlenA@4 referenced in function «void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)» (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__GetProcAddress@8 referenced in function «void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)» (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2001: unresolved external symbol __imp__GetProcAddress@8
    MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol __imp__LoadLibraryA@4 referenced in function «void __cdecl _RTC_AllocaFailure(void *,struct _RTC_ALLOCA_NODE *,int)» (?_RTC_AllocaFailure@@YAXPAXPAU_RTC_ALLOCA_NODE@@H@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2001: unresolved external symbol __imp__LoadLibraryA@4
    MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__QueryPerformanceCounter@4 referenced in function ___security_init_cookie
    MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetTickCount@0 referenced in function ___security_init_cookie
    MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentThreadId@0 referenced in function ___security_init_cookie
    MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetCurrentProcessId@0 referenced in function ___security_init_cookie
    MSVCRTD.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp__GetSystemTimeAsFileTime@4 referenced in function ___security_init_cookie
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__HeapFree@12 referenced in function «int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)» (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__HeapAlloc@12 referenced in function «int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)» (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__GetProcessHeap@0 referenced in function «int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)» (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__GetModuleFileNameW@12 referenced in function «int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)» (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__VirtualQuery@12 referenced in function «int __cdecl _RTC_GetSrcLine(unsigned char *,wchar_t *,unsigned long,int *,wchar_t *,unsigned long)» (?_RTC_GetSrcLine@@YAHPAEPA_WKPAH1K@Z)
    MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __imp__FreeLibrary@4 referenced in function «struct HINSTANCE__ * __cdecl GetPdbDll(void)» (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
    C:Usersanonymous64DesktopGAME\DEBUGMAIN — Game_DebugMAIN — Game.exe : fatal error LNK1120: 45 unresolved externals
    Build log was saved at «file://C:Usersanonymous64DesktopGAMEDEBUGMAIN — Game_DebugintermediateBuildLog.htm»

Answers

  • Then create a new project and add these files to the new project.

I hope this helps you! If not please see if you just missed out an extra step even though its complining just fine. You probably need to add an extra step somewhere.

Linker Tools Error LNK2001
unresolved external symbol «symbol»

Code will generate this error message if it references something (like a function, variable, or label) that the linker can�t find in all the libraries and object files it searches. In general, there are two reasons this error occurs: what the code asks for doesn�t exist (the symbol is spelled incorrectly or uses the wrong case, for example), or the code asks for the wrong thing (you are using mixed versions of the libraries?some from one version of the product, others from another version).

Numerous kinds of coding and build errors can cause LNK2001. Several specific causes are listed below, and some have links to more detailed explanations.

Coding Problems

Mismatched case in your code or module-definition (.DEF) file can cause LNK2001. For example, if you named a variable �var1� in one C++ source file and tried to access it as �VAR1� in another, you would receive this error. The solution is to exactly match the case of the symbol in all references.

A project that uses function inlining yet defines the functions in a .CPP file rather than in the header file can cause LNK2001.

If you are using C++, make sure to use extern �C� when calling a C function from a C++ program. By using extern �C� you force the use of the C naming convention. Be aware of compiler switches like /Tp or /Tc that force a file to be compiled as a C (/Tc) or C++ (/Tp) file no matter what the filename extension, or you may get different function names than you expect.

Attempting to reference functions or data that don’t have external linkage causes LNK2001. In C++, inline functions and const data have internal linkage unless explicitly specified as extern.

A missing function body or variable will cause LNK2001. Having just a function prototype or extern declaration will allow the compiler to continue without error, but the linker will not be able to resolve your call to an address or reference to a variable because there is no function code or variable space reserved.

Name decoration incorporates the parameters of a function into the final decorated function name. Calling a function with parameter types that do not match those in the function declaration may cause LNK2001.

Incorrectly included prototypes will cause the compiler to expect a function body that is not provided. If you have both a class and non-class implementation of a function F, beware of C++ scope-resolution rules.

When using C++, make sure that you include the implementation of a specific function for a class and not just a prototype in the class definition.

Attempting to call a pure virtual function from the constructor or destructor of an abstract base class will cause LNK2001 since by definition a pure virtual function has no base class implementation.

Only global functions and variables are public.
Functions declared with the static modifier by definition have file scope. Static variables have the same limitation. Trying to access any static variables from outside of the file in which they are declared can result in a compile error or LNK2001.

A variable declared within a function (a local variable) can only be used within the scope of that function.

C++ global constants have static linkage. This is different than C. If you try to use a global constant in C++ in multiple files you get error LNK2001. One alternative is to include the const initializations in a header file and include that header in your .CPP files when necessary, just as if it was a function prototype. Another alternative is to make the variable non-constant and use a constant reference when assessing it.

Compiling and Linking Problems

The names of the Microsoft run-time and MFC libraries needed at link time are included in the object file module by the Microsoft compiler. If you use the /NOD (/NODEFAULTLIB) option, these libraries will not be linked into the project unless you have explicitly included them. Using /NOD will cause error LNK2001 in this case.

If you are using Unicode and MFC, you will get an unresolved external on _WinMain@16 if you don�t create an entrypoint to wWinMainCRTStartup. Use the /ENTRY option or type this value in the Project Settings dialog box. (To find this option in the development environment, click Settings on the Project menu, then click the Link tab, and click Output in the Category box.) See Unicode Programming Summary.

See the following Knowledge Base articles located in the Online Information System for more information. An easy way to reach an article is to copy a «Q» number above, open the Search dialog box from the Help menu and select the Query tab, then paste the number into the first text box and press ENTER.
Q125750 «PRB: Error LNK2001: ‘_WinMain@16’: Unresolved External Symbol»

Q131204 «PRB: Wrong Project Selection Causes LNK2001 on _WinMain@16»

Q100639 «Unicode Support in the Microsoft Foundation Class Library»
Linking code compiled with /MT with the library LIBC.LIB causes LNK2001 on _beginthread, _beginthreadex, _endthread, and _endthreadex.

When compiling with /MD, a reference to «func» in your source becomes a reference «__imp__func» in the object since all the run-time is now held within a DLL. If you try to link with the static libraries LIBC.LIB or LIBCMT.LIB, you will get LNK2001 on __imp__func. If you try to link with MSVCxx.LIB when compiling without /MD you will not always get LNK2001, but you will likely have other problems.

Linking code compiled with an explicit or implicit /ML to the LIBCMT.LIB causes LNK2001 on _errno.

Linking with the release mode libraries when building a debug version of an application can cause LNK2001. Similarly, using an /Mxd option (/MLd, /MTd, or /MDd) and/or defining _DEBUG and then linking with the release libraries will give you potential unresolved externals (among other problems). Linking a release mode build with the debug libraries will also cause similar problems.

Mixing versions of Microsoft libraries and compiler products can be problematic. A new compiler version’s libraries may contain new symbols that cannot be found in the libraries included with previous versions. Use DUMPBIN to find out if a symbol is in a 32-bit object file or library.

There is currently no standard for C++ naming between compiler vendors or even between different versions of a compiler. Therefore linking object files compiled with other compilers may not produce the same naming scheme and thus cause error LNK2001.

Mixing inline and non-inline compile options on different modules can cause LNK2001. If a C++ library is created with function inlining turned on (/Ob1 or /Ob2) but the corresponding header file describing the functions has inlining turned off (no inline keyword), you will get this error. To prevent this problem, have the inline functions defined with inline in the header file you are going to include in other files.

If you are using the #pragma inline_depth compiler directive, make sure you have a value of 2 or greater set, and make sure you are using the /Ob1 or /Ob2 compiler option.

Omitting the LINK option /NOENTRY when creating a resource-only DLL will cause LNK2001.

Using incorrect /SUBSYSTEM or /ENTRY settings can cause LNK2001. For example, if you write a character-based application (a console application) and specify /SUBSYSTEM:WINDOWS, you will get an unresolved external for WinMain. For more information on these options and entry points, see the /SUBSYSTEM and /ENTRY linker options.
Export Problems

When you are porting an application from 16 to 32 bits, LNK2001 can occur. The current 32-bit module-definition (.DEF) file syntax requires that __cdecl, __stdcall, and __fastcall functions be listed in the EXPORTS section without underscores (undecorated). This differs from the 16-bit syntax, where they must be listed with underscores (decorated). For more information, see the description of the EXPORTS section of module-definition files.

Any export listed in the .DEF file and not found will cause LNK2001. This could be because it does not exist, is spelled incorrectly, or uses decorated names (.DEF files do not take decorated names).
This error message is followed by fatal error LNK1120.

The following sections give more detailed information on some of the issues named in the above list.

Missing function body or variable

Name decoration

The symbol is not public

Automatic (function scope) variables

Global constants in C++

Function inlining problems

Понравилась статья? Поделить с друзьями:
  • Error lnk2001 unresolved external symbol purecall
  • Error lnk2001 unresolved external symbol public
  • Error lnk2001 unresolved external symbol main
  • Error lnk2001 unresolved external symbol dllmaincrtstartup
  • Error lnk1104 cannot open file obj