error LNK2019: unresolved external symbol _LoadShaders referenced in function “void __cdecl init(void)” (?init@@YAXXZ)

前端 未结 3 691
一向
一向 2021-01-17 05:58

I am learning OpenGL and trying to run my first program. I have included all the files in include, lib, and bin folders. I have tried to add opengl32.lib;glut32.lib;glu32.li

相关标签:
3条回答
  • 2021-01-17 06:39

    The problem is from your LoadShaders function not having a body (presumably from your LoadShaders.h). Either locate the .cpp for LoadShaders, or link it's lib.

    If LoadShaders has a lib, since you're using VS 2012, you can use a preprocessor directive to link your lib:

    #pragma comment( lib, "yourlibfilename.lib" )
    

    Make sure your lib is actually where you say it is. By default Visual Studio will assume the lib resides in the same folder as the default folder for the source files.

    0 讨论(0)
  • 2021-01-17 06:55

    Only adding the libs in Linker->Input is not enough. The Linker will still not find them because your libs are in some arbitrary directory. Add the directory they are in to the setting Linker->General->additional library directories.

    0 讨论(0)
  • 2021-01-17 07:05

    You're missing the lib (or cpp) file for that LoadShaders() thing unless it's header only. Without knowing its contents we can't say that for sure.


    Update:

    The zip file with the book's source code includes everything you need.

    You should do the following:

    • Extract the zip file to an easy to remember location, e.g. "c:\openglbook".
    • Open or create your project in Visual Studio 2012.
    • Open the menu "PROJECT" and pick "[your project] Properties..." (or hit Alt+F7).
    • Repeat the following steps for each of your configurations or select "All Configurations" on the top left.
    • In the tree on the left open "Configuration Properties" and select "VC++ Directories".
    • Add c:\openglbook\include to "Include Directories".
    • Add c:\openglbook\lib to "Library Directories".
    • Close the project properties.
    • Copy the file "c:\openglbook\lib\LoadShaders.cpp" to your project files and add it as another source file.

    Once this is done your project should build. If you're still lacking dependencies, like GLUT functions, add the apropriate library from the "lib" sub directory to the linker libraries list you already know.

    0 讨论(0)
提交回复
热议问题