我试图在 msys 上使用 g++ 编译一个简单的 opengl 程序。令我惊讶的是,链接器抱怨未定义的引用:
$ g++ -mwindows -lopengl32 glut_md2.cpp
C:\Users\...\cceQtYAy.o:glut_md2.cpp:(.text+0x67a): undefined reference to `glGenTextures@8'
C:\Users\...\cceQtYAy.o:glut_md2.cpp:(.text+0x696): undefined reference to `glBindTexture@8'
....
谷歌搜索了一段时间后,我发现问题出在 g++ 参数顺序中:
$ g++ glut_md2.cpp -mwindows -lopengl32
--- all ok! ---
有趣的是,g++ 中正确的参数顺序在第一个示例中。那是:
$ g++ --help
Usage: g++.exe [options] file...
....
我错过了什么吗?为什么在 file 参数之后移动选项会使编译成功?在linux上本地编译时我从来没有遇到过这个问题......