【问题标题】:Dependency Cycle Scons GLEW, GLFW依赖周期 Scons GLEW, GLFW
【发布时间】:2014-10-01 23:46:54
【问题描述】:

我正在尝试将 GLEW 和 GLFW dll 链接到我的项目。我正在使用 SCons 来制作。我的 SConstruct 文件是:

env=Environment();
env.SharedLibrary('glfw3.dll');
env.SharedLibrary('glew32.dll');
env.Program('tutorial01.cpp');

glfw3.dll 和 glew32.dll 都在 C:\Windows\System32 中。当我尝试构建它时,这是构建结果:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
link /nologo /OUT:tutorial01.exe tutorial01.obj
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glClearColor referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol glewInit referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwInit referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwTerminate referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwWindowHint referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwCreateWindow referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwWindowShouldClose referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwPollEvents referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwSetInputMode referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwGetKey referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwMakeContextCurrent referenced in function main
tutorial01.obj : error LNK2019: unresolved external symbol __imp_glfwSwapBuffers referenced in function main
tutorial01.exe : fatal error LNK1120: 12 unresolved externals
scons: *** [tutorial01.exe] Error 1120
scons: building terminated because of errors.

scons: *** Found dependency cycle(s):
  glew32.lib -> glew32.lib
  glfw3.dll -> glfw3.dll

File "C:\Python27\Scripts\..\Lib\site-packages\scons-2.3.3\SCons\Taskmaster.py", line 1043, in cleanup
[Finished in 0.9s with exit code 2]
[cmd: ['C:\\Python27\\Scripts\\Scons.bat']]
[dir: C:\Users\mark\programming\sublime-try2]
[path: C:\PROGRAM FILES (X86)\INTEL\ICLS CLIENT\;C:\PROGRAM FILES\INTEL\ICLS CLIENT\;C:\PHP\;C:\PROGRAM FILES (X86)\JAHSHAKA\..\MLT\BIN;C:\PROGRAM FILES (X86)\OPENLIBRARIES\BIN;;C:\NODEJS\;C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\PROGRAM FILES (X86)\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\DAL;C:\PROGRAM FILES (X86)\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\IPT;C:\PROGRAM FILES\MICROSOFT SQL SERVER\110\TOOLS\BINN\;C:\PROGRAM FILES (X86)\QUICKTIME\QTSYSTEM\;C:\PROGRAM FILES\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\DAL;C:\PROGRAM FILES\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\IPT;C:\PROGRAM FILES (X86)\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\DAL;C:\PROGRAM FILES (X86)\INTEL\INTEL(R) MANAGEMENT ENGINE COMPONENTS\IPT;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files (x86)\K-3D 0.8.0.1\bin;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\;C:\Python27\Scripts\;C:\Users\mark\AppData\Roaming\npm]

暂时忽略链接错误,最后一部分是什么意思,它说“找到依赖循环”?那很重要吗?难道我做错了什么?另外,tutorial01.cpp 来自 opengl-tutorial.org,但做了一些修改:

// Include standard headers
#include <stdio.h>
#include <stdlib.h>

// we're building a static!

#define GLEW_STATIC

// Include GLEW
#include <GL/glew.h>

// so it works with dll
#define GLFW_DLL

// Include GLFW
#include <glfw3.h>
GLFWwindow* window;

// Include GLM
#include <glm/glm.hpp>
using namespace glm;

int main( void )
{
    // Initialise GLFW
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    // Open a window and create its OpenGL context
    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
    if( window == NULL ){
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
        glfwTerminate();
        return -1;
    }
    glfwMakeContextCurrent(window);

    // Initialize GLEW
    if (glewInit() != GLEW_OK) {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }

    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    // Dark blue background
    glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

    do{
        // Draw nothing, see you in tutorial 2 !

        // Swap buffers
        glfwSwapBuffers(window);
        glfwPollEvents();

    } // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
           glfwWindowShouldClose(window) == 0 );

    // Close OpenGL window and terminate GLFW
    glfwTerminate();

    return 0;
}

头文件也正确地位于 Visual Studio 的包含文件夹中

任何想法为什么我得到依赖循环错误?还是链接错误?

【问题讨论】:

    标签: c++ dependencies scons glfw glew


    【解决方案1】:

    SharedLibrary 方法不是用于指定您要使用 DLL,而是创建它们。要使用已经存在的库/DLL,您必须将其名称添加到 LIBS 环境变量中,从那里获取它以进行实际的链接器调用。

    您看到的依赖错误与您尝试创建一个已经存在的 DLL 直接相关。

    从您所写的内容来看,您似乎只是从 SCons 开始...所以我的建议是查看 UserGuide(请参阅 http://www.scons.org/doc/production/HTML/scons-user.html 以获取 HTML 版本)并至少浏览简单的示例.

    【讨论】:

    • 好的,我会尝试您的建议,并在(如果)有效时回复您!另外,LIBS 环境变量是 C++ 还是 SCons?
    • 好的,我相信我已经在 Program 调用中使用 LIBS 和 LIBPATH 修复了我的 SConstruct 文件,但它会自动将 .lib 添加到我放置的库名称的末尾。我怎样才能将 dll 添加到一个末尾?
    • 尝试在名称末尾添加.dll,但它仍然不起作用。我目前正在处理这个SConstruct 文件:env=Environment(); env.Program(['tutorial01.cpp'], LIBS=['glfw3','glfw3dll','glew32'], LIBPATH=['C:\\Windows\\System32','C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\lib']);
    • 好的,我现在明白了,你包含了一个.lib,然后.lib 包含了你的dll,所以我只包含了GLEW 和GLFW 的.lib 文件。但是,我仍然收到一个错误:LINK : error LNK2001: unresolved external symbol mainCRTStartup 有什么建议吗?
    • Nvm,摆脱了那个错误,现在我又得到了一个。对不起所有这些 cmet,我会闭嘴,直到我有更确凿的话要说
    猜你喜欢
    • 1970-01-01
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多