Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: The compiler shows linker errors for a project

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    24

    The compiler shows linker errors for a project

    Hi all,

    Finally I could set the Visual Studio 2017 for OpenGL.
    I created an Empty Project named opengl. Then tested this code on it.
    The output is two windows as in here.

    Is it fine that the Visual Studio shows two windows for this project? I mean, is my result the same as yours?

    Then I pasted this code this time into the project. The output is this.

    It seems that everything is OK.

    Since I'm reading the book "OpenGL.Programming.Guide.9th.Edition" and in page 40, it offers a first code named Example1.1 with this code:

    Code :
    #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;
    //--------------------------------------------------------------------
    //
    // init
    //
    void
    init(void)
    {
    	static const GLfloat vertices[NumVertices][2] =
    	{
    		{ -0.90, -0.90 }, // Triangle 1
    		{ 0.85, -0.90 },
    		{ -0.90, 0.85 },
    		{ 0.90, -0.85 }, // Triangle 2
    		{ 0.90, 0.90 },
    		{ -0.85, 0.90 }
    	};
    	glCreateBuffers(NumBuffers, Buffers);
    	glNamedBufferStorage(Buffers[ArrayBuffer], sizeof(vertices),
    		vertices, 0);
    	ShaderInfo shaders[] = {
    		{ GL_VERTEX_SHADER, "triangles.vert" },
    		{ GL_FRAGMENT_SHADER, "triangles.frag" },
    		{ GL_NONE, NULL }
    	};
    	GLuint program = LoadShaders(shaders);
    	glUseProgram(program);
    	glGenVertexArrays(NumVAOs, VAOs);
    	glBindVertexArray(VAOs[Triangles]);
    	glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    	glVertexAttribPointer(vPosition, 2, GL_FLOAT,
    		GL_FALSE, 0, BUFFER_OFFSET(0));
    	glEnableVertexAttribArray(vPosition);
    }
    //--------------------------------------------------------------------
    //
    // display
    //
    void
    display(void)
    {
    	static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    	glClearBufferfv(GL_COLOR, 0, black);
    	glBindVertexArray(VAOs[Triangles]);
    	glDrawArrays(GL_TRIANGLES, 0, NumVertices);
    }
    //--------------------------------------------------------------------
    //
    // main
    //
    int
    main(int argc, char** argv)
    {
    	glfwInit();
    	GLFWwindow* window = glfwCreateWindow(640, 480, "Triangles", NULL,
    		NULL);
    	glfwMakeContextCurrent(window);
    	gl3wInit();
    	init();
     
    	while (!glfwWindowShouldClose(window))
    	{
    		display();
    		glfwSwapBuffers(window);
    		glfwPollEvents();
    	}
     
    	glfwDestroyWindow(window);
    	glfwTerminate();
    }

    so this time, I pasted this code to the project. It shows no red lines but when I runt it, I get these 13 errors:
    https://s1.postimg.org/6yp2zukgcf/Capture.png

    Why do I get these errors for this specific code and how to solve it please?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    Quote Originally Posted by Tomyfr View Post
    these 13 errors:
    https://s1.postimg.org/6yp2zukgcf/Capture.png

    Why do I get these errors for this specific code and how to solve it please?
    The unresolved symbols on link imply that you are not linking in the library "glfw3.lib" (or "glfw3_d.lib" in debug mode). This library is in the examples/lib/ directory in the book examples build tree.

    The book example build files link this library for you.

  3. #3
    Member Regular Contributor
    Join Date
    Jul 2012
    Posts
    420
    Quote Originally Posted by Tomyfr View Post
    Is it fine that the Visual Studio shows two windows for this project? I mean, is my result the same as yours?
    Yes. You have the Windows console window, plus the OpenGL window.
    If you don't want the console, there are some things (or options) to do (or change) in Visual Studio. I don't remember them, and I suggest you to keep it for now, since it will allow you to output relevant and important information.

    Quote Originally Posted by Tomyfr View Post
    It shows no red lines but when I runt it, I get these 13 errors:
    https://s1.postimg.org/6yp2zukgcf/Capture.png

    Why do I get these errors for this specific code and how to solve it please?
    I would suggest you to read articles about compilation and linking. This is essential when programming with languages like C or C++. Here are a few top results returned by google here:

    https://www.cprogramming.com/compilingandlinking.html
    https://stackoverflow.com/questions/...g-process-work

  4. #4
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    24
    Quote Originally Posted by Dark Photon View Post
    The unresolved symbols on link imply that you are not linking in the library "glfw3.lib" (or "glfw3_d.lib" in debug mode).
    I entered the name of that lib fine in the Linker > Input and ran the code this time. Here is the output.

    The error says that it can't open that lib file. It's logical because I haven't got that file in the lib folder. Now I think I need only that lib file to put into that folder and run the code again.

    This library is in the examples/lib/ directory in the book examples build tree.
    I don't have that directory unfortunately.

  5. #5
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    24
    Yes. You have the Windows console window, plus the OpenGL window.
    If you don't want the console, there are some things (or options) to do (or change) in Visual Studio. I don't remember them, and I suggest you to keep it for now, since it will allow you to output relevant and important information.
    OK, thanks.

    I would suggest you to read articles about compilation and linking. This is essential when programming with languages like C or C++. Here are a few top results returned by google here
    Thank you, I read it.
    I also knew somewhat about these and added the addresses of include and libraries folders to the Properties of the project.
    I assume I only need that lib file to retest the code again.

  6. #6
    Junior Member Newbie
    Join Date
    Sep 2017
    Posts
    24
    No further guide?!
    Have you tested this code on your VS?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •