Sign in to follow this  
phil67rpg

linker error 2019

Recommended Posts

phil67rpg    443

I am working with a shader program for the first time I got it out of the opengl programming guide eight edition "orange book", I am getting the following linker error. I have included the include file folder and the lib file folder into vs 2012. here is the error I am getting:

Error 2 error LNK2019: unresolved external symbol _LoadShaders referenced in function "void __cdecl init(void)" (?init@@YAXXZ) C:\Users\Phillip\Desktop\triangles\triangles\triangles.obj triangles
 

 

Share this post


Link to post
Share on other sites
BitMaster    8651
You are calling a function _LoadShaders (minus a bit of name mangling) in your function init(). That function has been declared but never implemented. You are probably not linking a .cpp you would have to link.

Share this post


Link to post
Share on other sites
phil67rpg    443

here  is the code I got out of the book

#include
 
 
<iostream>
using
 
 
namespace std;
#include
 
 
"vgl.h"
#include
 
 
"LoadShaders.h"
enum
 
 
VAO_IDs { Triangles, NumVAOs };
enum
 
 
Buffer_IDs { ArrayBuffer, NumBuffers };
enum
 
 
Attrib_IDs { vPosition=0 };
GLuint
 
 
VAOs[NumVAOs];
GLuint
 
 
Buffers[NumBuffers];
const
 
 
GLuint NumVertices = 6;
void
 
 
init(void)
{
 
 
glGenVertexArrays(NumVAOs, VAOs);
 
 
glBindVertexArray(VAOs[Triangles]);
 
 
GLfloat vertices[NumVertices][2] = {
{ -0.90, -0.90 },
{ 0.85, -0.90 },
{ -0.90, 0.85 },
{ 0.90, -0.85 },
{ 0.90, 0.90 },
{ -0.85, 0.90 }
};
 
 
glGenBuffers (NumBuffers, Buffers);
 
 
glBindBuffer (GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
 
 
glBufferData (GL_ARRAY_BUFFER, sizeof(vertices),vertices,GL_STATIC_DRAW);
 
 
ShaderInfo shaders[] = {
{ 
 
GL_VERTEX_SHADER, "triangles.vert" },
{ 
 
GL_FRAGMENT_SHADER, "triangles.frag" },
{ 
 
GL_NONE, NULL }
};
 
 
GLuint program = LoadShaders(shaders);
 
 
glUseProgram (program);
 
 
glVertexAttribPointer(vPosition,2,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(0));
 
 
glDisableVertexAttribArray(vPosition);
}
void
 
 
display(void)
{
glClear(
 
GL_COLOR_BUFFER_BIT);
 
 
glEnableVertexAttribArray(VAOs[Triangles]);
glDrawArrays(
 
GL_TRIANGLES,0,NumVertices);
glFlush();
}
int
 
 
main(int argc, char** argv)
{
 
 
glutInit(&argc,argv);
glutInitDisplayMode(
 
GLUT_RGBA);
glutInitWindowSize(512,512);
glutInitContextVersion(4,3);
glutInitContextProfile(
 
GLUT_CORE_PROFILE);
 
 
glutCreateWindow(argv[0]);
 
 
if (glewInit()) {
cerr << 
 
"Unable to initialize GLEW ... exiting" << endl;
exit(
 
EXIT_FAILURE);
}
init();
glutDisplayFunc(display);
glutMainLoop();
}

 

?

Share this post


Link to post
Share on other sites
Bacterius    13165

It's not the code. The code is (presumably) fine since you took it out of a book. It's a linker error which means the problem is in how you are compiling the code (you are likely not linking to a library you need, linking to an outdated version of the library, or doing something else wrong). What libraries are you linking against? How are you compiling your code? What is your command-line (or, equivalently, what are your IDE settings?)

Share this post


Link to post
Share on other sites
BitMaster    8651

well I linked in all the libs I could find


It is highly unlikely that adding random libraries will get you anywhere. The function you are missing is almost certainly written by the author of the program and not available in any external library.

There is a LoadShaders.h included. Most likely there will be a LoadShaders.cpp lying around. That file must be compiled as well and the resulting object files linked. Since you appear to be using MSVC it will probably be enough to add the the file to the project in the solution.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this