2017-04-20 75 views
0

我创建了使用GLEW库工作,我有下一段代码:GLEW不会在自己的图书馆

// ShaderProgram.hpp 
#include <GL.hpp> 
#include <vector> 

namespace LIBRARY { 
    class LIBRARY_API ShaderProgram { 
    public: 
     ShaderProgram() { 
      // If I uncomment the code will works, but why it doesn't work without because I already initialize GLEW in the main() function 
      // glewExperimental = GL_TRUE; 
      // std::cout << (glewInit() == GLEW_OK) << "\n"; // <- Outputs true 

      std::cout << (glCreateProgram) << "\n" // <- Null function! 
      m_program = glCreateProgram(); // <- Here crash when trying to call glCreateProgram(), I mean it can't find the function 
     } 
    }; 
} 

这是我的代码库的一部分。然后,我创建了一个小的应用程序来测试它,我用SFML窗:

int main() { 
... 

sf::Window window(sf::VideoMode(800, 600, 32), "OpenGL", sf::Style::Titlebar | sf::Style::Close, settings); 
window.setFramerateLimit(60); 

window.setActive(true); 

glewExperimental = GL_TRUE; 
std::cout << (glewInit() == GLEW_OK) << "\n"; // <- Outputs true 

std::cout << (glCreateProgram) << "\n" // <- Not null function adress, so it's good!  

LIBRARY::ShaderProgram shaderProgram; // <- Here crash 
... 

因此,在main()的glCreateProgram不为空,它可调用的函数,但在库是空,我可以不明白为什么,因为我在glew init之后调用库代码,因为它可以在构建ShaderProgram的代码中看到。

Thread 1 received signal SIGSEGV, Segmentation fault. 
0x00000000 in ??() 
(gdb) bt 
#0 0x00000000 in ??() 
#1 0x68a015a2 in LIBRARY::ShaderProgram::ShaderProgram()() 
    from path\to\my\library.dll 
#2 0x00401843 in main() 

我不明白为什么在应用程序GL工作,但在图书馆它没有。

编辑:编辑代码更好地说明这个问题。

+0

在调试配置中编译DLL + EXE,并用调试器启动它。它可能马上告诉你这个问题。 – Soonts

+0

另外,您可能需要查看和/或重新使用我的这个项目:https://github.com/Const-me/GL3Windows(MIT许可证)。这是一个小而合理完整的现代OpenGL Windows样本,包括GLEW,着色器和VBO。 – Soonts

+0

在您的GL.hpp中使用[#include guards](https://en.wikipedia.org/wiki/Include_guard),看看它是否有帮助。 – Ripi2

回答

0

的问题是,我是静态链接GLEW。通过动态链接解决。