glfw示例文件编译不过的解决.思路在于观察到libcmt与msvcrt冲突

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/fqbqrr/article/details/98775403

编译这个glfw示例文件时,总是一大堆链接错误:

#include <GLFW/glfw3.h>
#pragma comment(lib,"glfw3.lib")

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

找了半天,后来加了user32.lib,gdi32.lib,少了些链接错误.然后各种折腾,也搞不定.
一大堆如下错误:

glfw3.lib(wgl_context.obj) : error LNK2019: 无法解析的外部符号 __imp__SwapBuffers@4,该符号在函数 _swapBuffersWGL 中被引用
MSVCRT.lib(chandler4gs.obj) : error LNK2019: 无法解析的外部符号 __except_handler4_common,该符号在函数 __except_handler4 中被引用
示例.exe : fatal error LNK1120: 102 个无法解析的外部命令

后来才想到可能是动态链接与静态链接不匹配的问题,以后只要是链接错误,都要往这方面想,即链接方式不匹配.
这主要是直接就把别人的项目拿来编译.虽然都编译通过了.但编译方式不一样.或者可能是我用cmake生成编译文件时搞错了.不能选动态编译.要静态编译.可能cmake的某个编译方式时没认真看.点错了.
然后就批量修改一大堆vcxproj文件.
注意,两个替换:

MultiThreadedDebugDLL,MultiThreaded
MultiThreadedDLL,MultiThreaded

然后编译glfw成功.然后用这个编译成功的再编译上面的文件.vs就编译过了.但命令行未编译过,cl额外连接添加vs选项里面的额外连接.就成功了.

猜你喜欢

转载自blog.csdn.net/fqbqrr/article/details/98775403