GLFW链接不能正常工作与mingw32在c++ (?)
GLFW link not working correctly with mingw32 in C++ (?)
我试图从GLFW
网页编译这个例子:
#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 */
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
我使用mingw32,我从这里下载了32位windows二进制文件http://www.glfw.org/download.html.
我把它们放在各自的文件夹中:
C:ProgrammingMinGW32bin
中的glfw3.dll
和我的main.cpp
文件夹中的副本。
C:ProgrammingMinGW32lib
中的glfw3dll.a
和libglfw3.a
GLFW folder
及其。h文件在C:ProgrammingMinGW32include
g++ -lglfw3dll -lopengl32 main.cpp -Wall -o main.exe
下面是我得到的错误:
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0xf): undefined reference to `glfwInit'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x4e): undefined reference to `glfwCreateWindow'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x5e): undefined reference to `glfwTerminate'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x71): undefined reference to `glfwMakeContextCurrent'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x7f): undefined reference to `glfwSwapBuffers'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x84): undefined reference to `glfwPollEvents'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x90): undefined reference to `glfwWindowShouldClose'
D:UsersJorgeAppDataLocalTempccA4Wc7r.o:animation.cpp:(.text+0x9e): undefined reference to `glfwTerminate'
C:ProgrammingMinGW32bin/ld.exe: D:UsersJorgeAppDataLocalTempccA4Wc7r.o: bad reloc address 0x20 in section `.eh_frame'
C:ProgrammingMinGW32bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
我可以看到链接器在某种程度上无法与glfw链接,但为什么?我做错了什么?由于
您用来编译的命令出了问题。应该是:
g++ main.cpp -lglfw3dll -lopengl32 -lgdi32 -Wall -o main.exe
这是因为您首先编译main.cpp,然后将库链接到它。gdi32
库在创建OpenGL上下文时也是需要的。
相关文章:
- Mingw32无法静态链接到libgcc_s_dw2-1、libstdc++-6、libwinpthread-1(Qt
- mingw32-make 使用"MinGW Makefiles"生成器跟踪 CMAKE 无法将可执行文件链接到对象库
- mingw32_gt_pch_use_address中的内部错误,在config/i386/host-mingw32.c
- 使用 x86_64-w64-mingw32-g++ 编译 JNI C++本机代码
- 提升日志链接错误(Cmake Mingw32)
- mingw32-make '-j' 选项是否损坏
- C++ Mingw32 创建进程() 失败,错误代码 2:系统找不到指定的文件
- mingw32/bin/ld.exe:找不到 -lfl collect2.exe:错误:ld 返回 1 个退出状态
- 如何修复链接器错误"mingw32/bin/ld.exe: cannot find -lSDL"?
- 无法将 Linux openGL 程序与 mingw32 交叉编译。配置.log错误:未定义对"_glEnable"的引用
- cmd 命令启动无法与新版本的 mingw32-make.exe一起使用?
- 如何解决 mingw32-make.exe退出代码 2 错误
- MINGW32(OGRE3D CEGUI GLM应用程序)的标题冲突错误
- 启用 MingW32-make -j 上的 50% 核心利用率
- 未定义的引用 C++ MingW32
- 在哪里可以找到与Clang假设的目录结构相同的mingw32
- /Mingw32/bin/ld.exe: cannot find -llibcurl?
- 如何使用 bjam 在 cygwin windows7 i686-w64-mingw32-g++ 中编译 Boost(和
- Mingw32-w64 GCC 4.9.2 正则表达式错误,或者我不知道C++
- Mingw32中对"SDL_main"的未定义引用