LNK2019: unresolved external symbol error when i compile my win32 app
- I am kinda new at this c++, and i am try to to make a Open GL application that when run will make a cube and rotate it on the screen. When i compile my project I get the about 21 different "LNK2019: unresolved external symbol errors". maybe some one can help me figure this out. If you need the project files I can send it too you. I am using visual studio C++ .net 2003. I also tried this code in visual 2005 and received the same thing.
the error i received are as follows:
Error Messages:
OpenGLCube.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glHint@8 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glDepthFunc@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glClearDepth@8 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glShadeModel@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "int __cdecl UpdateScene(void)" (?UpdateScene@@YAHXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function "void __cdecl KillGLWindow(void)" (?KillGLWindow@@YAXXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "void __cdecl KillGLWindow(void)" (?KillGLWindow@@YAXXZ)
OpenGLCube.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "int __cdecl InitInstance(struct HINSTANCE__ *,int,int,int)" (?InitInstance@@YAHPAUHINSTANCE__@@HHH@Z)
Debug/OpenGLCube.exe : fatal error LNK1120: 20 unresolved externals
Answers
Right click on your project, choose Properties. Then Linker, then Input. From these three libraries, add the ones that contain the symbols listed at the top. I would do this empirically: just add them and see if the linker errors go away.
But you can also determine the contents of the libs by using dumpbin.exe. On the command line, set the path by running either \Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat or \Program Files\Microsoft Visual Studio 8\vc\vcvarsall.batAnd then invoke dumpbin.exe: dumpbin.exe /exports CLU32.lib
If these import libraries contain your symbols, you're set to go. Remember that the corresponding DLL's must be on the path or the same directory as the executable when you run it.
Note that dumpbin.exe can also be used on the DLL's themselves: dumpbin.exe /exports CLU32.dllBrian
PS If you can, reedit your first post and delete the source code. It's not relevant to the problem and makes this thread hard to read. Thanks.You need to link against the OpenGL import library (something.lib). Add the name of this file to your linker settings.
- basically whatis happening is you have to use the exact symbol that is located in your lib file, it could be a spelled wrong, also it is case sensitive.
for example:
example.lib ---> contains
==================================
scope() ---> symbol in lib file
create() ---> symbol in lib file
pick() ---> symbol in lib file
==================================
whenyou use the symbol contained in the lib file.
example code:
======================================================
int main()
{
if (c > 100)
create() // referenced symbol same as what is in your lib file
// symbol referenced is case-sensitive
} // end main
=======================================================
All Replies
You need to link against the OpenGL import library (something.lib). Add the name of this file to your linker settings.
- How do i go about linking the library's to the linker settings, i have three OpenGL lib files i put in the project directory. (GLU32.lib, GLUT32.lib, and OpenGL32.lib). How to i add these lib file to the linker setting? And are these the right lib files? Also would it help if i email you the project files. if so i need your email address, mine is lew26@msn.com .
Right click on your project, choose Properties. Then Linker, then Input. From these three libraries, add the ones that contain the symbols listed at the top. I would do this empirically: just add them and see if the linker errors go away.
But you can also determine the contents of the libs by using dumpbin.exe. On the command line, set the path by running either \Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin\vcvars32.bat or \Program Files\Microsoft Visual Studio 8\vc\vcvarsall.batAnd then invoke dumpbin.exe: dumpbin.exe /exports CLU32.lib
If these import libraries contain your symbols, you're set to go. Remember that the corresponding DLL's must be on the path or the same directory as the executable when you run it.
Note that dumpbin.exe can also be used on the DLL's themselves: dumpbin.exe /exports CLU32.dllBrian
PS If you can, reedit your first post and delete the source code. It's not relevant to the problem and makes this thread hard to read. Thanks.- ok, thanks for everything i sure learned alot from you.
wheni try to compile my app i get this error:
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
Debug\Employee.exe : fatal error LNK1120: 1 unresolved externals
please tell me how to fix it- Define the main() function.
- basically whatis happening is you have to use the exact symbol that is located in your lib file, it could be a spelled wrong, also it is case sensitive.
for example:
example.lib ---> contains
==================================
scope() ---> symbol in lib file
create() ---> symbol in lib file
pick() ---> symbol in lib file
==================================
whenyou use the symbol contained in the lib file.
example code:
======================================================
int main()
{
if (c > 100)
create() // referenced symbol same as what is in your lib file
// symbol referenced is case-sensitive
} // end main
======================================================= - Hi Brian
I have done all as said in your post. But i dont understand what do u mean when u say the .dll have to be in the same directory as the exe.
I am trying to setup opengl on my computer. I am using windows Xp and have placed all .dll files in the system32 folder. I have the .lib files in the \Program Files\Microsoft Visual Studio 8\vc\lib. I have the libs added to the linker settings in the visual studio.
I have done the dumpbin.exe to tally the symbols used in the program and those present in the .lib and .dll files.
Still the compilation fails with the same error.
What else needs to be done?
Thanks and Regards
pk - I have exactly the same problem.. Anyone solved this yet?
Saying it at the beginning, I am not an expert.
I got the same problem every now and then. Normally I could solve it by include the .lib file and/or if the function is not defined in the .cpp, define it in the .cpp file.
Today the problem I have experienced is a bit more "nasty", took me a few hours to solve it. (Different solution but same error message I think)
Basically I was using a colleage's .h and .cpp file (copied from one project into another). Within the .h file it included say, "nasty.h", within this "nasty.h", it contains tons of #ifndef, #define ... and export and extern, etc. I included the "nasty.lib" and the problem was still there. I copied the Preprocessor Definitions (used in the project that I copied those files from), and it solved the problem! It's easy to tell, but not when you are exploring the solution.
So this might be a solution for you:
In Visual C++ (.Net 2003), click on the menu Project -> (project name) Properties -> Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
and check if the ones defined there are correct.
- that was very helpful DJ, thanks! it works for my problem

- Hello,
I havnt a clue what is coing on with these three errors.
I think its somthing to do with the linker. but I have not dealt much with that yet.
here is the error:
1>moc_mavcom.obj : error LNK2019: unresolved external symbol "private: void __thiscall Mavcom::on_pushButton_clicked(void)" (?on_pushButton_clicked@Mavcom@@AAEXXZ) referenced in function "public: virtual int __thiscall Mavcom::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Mavcom@@UAEHW4Call@QMetaObject@@HPAPAX@Z)1>moc_about.obj : error LNK2019: unresolved external symbol "private: void __thiscall about::on_textBrowser_textChanged(void)" (?on_textBrowser_textChanged@about@@AAEXXZ) referenced in function "public: virtual int __thiscall about::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@about@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
1>moc_about.obj : error LNK2019: unresolved external symbol "private: void __thiscall about::on_pushButton_clicked(void)" (?on_pushButton_clicked@about@@AAEXXZ) referenced in function "public: virtual int __thiscall about::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@about@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
Thanks in advance - Barb3958, in future, create a new thread for a new question, rather than resurrecting a dead thread that nobody cares about anymore.
Quite simply, you are using three functions in your program:
on_pushButton_clicked()
on_textBrowser_textChanged()
on_pushButton_clicked()
but they are not implemented anywhere where the linker can find them. - O! Ok,
Sorry I am new to forums. I will not do that again.
Thank you, that helped alot. - well try changing ur subsystem from console to windows from the project solutions /input/systems..

