Jump to content

  • Log In with Google      Sign In   
  • Create Account

linker error 2019


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
12 replies to this topic

#1   Members   

216
Like
0Likes
Like

Posted 20 August 2013 - 09:55 PM

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
 

 



#2   Members   

8647
Like
0Likes
Like

Posted 21 August 2013 - 02:48 AM

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.

#3   Members   

1036
Like
0Likes
Like

Posted 21 August 2013 - 11:06 AM

_LoadShaders ... is that supposed to be a function or a member variable?  How is this defined in your code?


---
Free C++, OpenGL, and Game Development Video Tutorials @
www.MarekKnows.com
Play my free games: Ghost Toast, Zing, Jewel Thief


#4   Members   

216
Like
0Likes
Like

Posted 21 August 2013 - 03:40 PM

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();
}

 

 



#5   Members   

13102
Like
0Likes
Like

Posted 21 August 2013 - 03:46 PM

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?)


“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”


#6   Members   

216
Like
0Likes
Like

Posted 21 August 2013 - 04:36 PM

well I linked in all the libs I could find and all the include directories. I am using vs2012. I am running out of options. sorry but I am still stuck.



#7   Members   

216
Like
0Likes
Like

Posted 21 August 2013 - 08:27 PM

well I have tried everything I can think of but to no avail.



#8   Members   

8647
Like
0Likes
Like

Posted 22 August 2013 - 01:10 AM

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.

#9   Members   

216
Like
0Likes
Like

Posted 22 August 2013 - 01:41 PM

well I added the .cpp files but it still does not work



#10   Members   

1036
Like
0Likes
Like

Posted 22 August 2013 - 01:59 PM

could you post the code found in the .cpp file here


---
Free C++, OpenGL, and Game Development Video Tutorials @
www.MarekKnows.com
Play my free games: Ghost Toast, Zing, Jewel Thief


#11   Members   

216
Like
0Likes
Like

Posted 22 August 2013 - 02:23 PM

Attached File  cpp file.zip   1.09KB   28 downloadswell here is the loadshaders.cpp file.

 



#12   Members   

1902
Like
0Likes
Like

Posted 22 August 2013 - 02:31 PM

Did you try moving the include below the extern "C" line like the following:


#ifdef __cplusplus
extern "C" {
#endif // __cplusplus


#include "LoadShaders.h"



#13   Members   

216
Like
0Likes
Like

Posted 22 August 2013 - 02:37 PM

well I tried the above but it still does not work






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.