Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

Why link error when try to build simple OpenGL project?

I'm using Visual Studio Community 2019.
I found 'OpenGL C++ Tutorial : Getting Started' on youtube.   I get error when I try to link project.  Maybe I'm not specifying 'Additional Dependencies' correctly in my project setting.  Please see attached.

Also, attached is the link error.
Additional_dependencies.PNG
lib_in_proj_folder.PNG
link_error.PNG
Avatar of naseeam
naseeam
Flag of United States of America image

ASKER

I downloaded 32-bit GLFW library.  Since I have 64-bit machine, do I need to download 64-bit windows library instead?
https://www.glfw.org/download.html
Avatar of Juan Carlos
Inaddidional  independence  include extensión: glfw3.lib;...
Remove from adicional depende glfw3
Avatar of naseeam

ASKER

I added file extension in 'Additional Dependencies', now I get following link error:

User generated image
Avatar of naseeam

ASKER

Initially, before adding libraries to 'Additional Dependencies', I deleted everything from this field and then added libraries told by the
youtube tutorial.  Does %(Additional Dependencies) need to be at the end of 'Additional Dependencies' field?

Do I need to specify path to the glfw library in visual studio?
Yes, you need to include library path in VC Directories:
Include Directory

Library Directory

First for .h and sec9nd for objetos and .h.

Ignore my previous coments and ensure you are include the path en VCDirectorie
Avatar of naseeam

ASKER

Build succeeded but following linker warning?

User generated image
Conflits between c++ libs and glfw3 libs: Verify that both libraries have the same threading:  Multithread / Not Multithread.

maybe you are compiling your project as multithraead and the libraries are not multithread
Avatar of naseeam

ASKER

My project only has One function, main( ).  There are no threads in this function.  

#include <GLFW/glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

Open in new window


I  downloaded 32-bit Windows binaries from:  https://www.glfw.org/download.html.  Is this the reason for linker warning?

Instead of binaries, downloading 'Source Package' and compiling into library will eliminate this warning?
Your are using glfw3 for lib-vc2019.  Yor visual studio is 2019?  If not then change the libraries and include Directories in VCDirectories configuration to lib-yourvsversion.

The reason of the warnning is different msvcrt runtime
Included Directory is then same only modify in LIbraries Dictories lib-vc2019 to lib-vc2010 if you are using vs 2010 for example
Avatar of naseeam

ASKER

I'm using Visual Studio Community 2019
Check

General Configuration:

Platform Toolset : visual Studio 2019 (v142)

C/C++:

Use Runtime Libraru: /MD
Alternative: create New project and install glfw library from Nuget Package Administrator.
Using: Runtime Library:  /MD no warnings. Default is /MDd for debug y /MD for Realease (no debug simbols).  Library glfw3.lib  is Release no debug this is reason of warnning.
Avatar of naseeam

ASKER

What is " /NODEFAULTLIB:library "  Do I need to use some no default library instead of 'MSVCRT' ?

User generated image
ASKER CERTIFIED SOLUTION
Avatar of Juan Carlos
Juan Carlos
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
remember: when you change to Release you will have to configure the inclusion directories and libraries, as well as the additional libraries again for this environment
Avatar of naseeam

ASKER

Expert found root cause of compiler warning.  Thank you!