【发布时间】:2020-10-16 11:04:38
【问题描述】:
我正在尝试编译 2 个在 MacOs 上使用 OpenGL 和 fltk 的 .cpp 文件。
在使用 linux (Fedora) 的设备上,我使用以下命令:
g++-9 -std=c++17 window.cpp prova.cpp -o test -lfltk -lGL -lglut -lGLU -lfltk_gl
一切正常。
在 Mac_Os 终端上,我尝试使用:
g++ -framework GLUT -framework OpenGL -lGLU -lfltk -lglut -lGL -framework Cocoa window.cpp prova.cpp 我收到无数错误(我在 linux 上没有)和警告:
(Define GL_SILENCE_DEPRECATION to silence these warnings) [-Wdeprecated-declarations]
inline void gl_rectf(int x,int y,int w,int h) {glRecti(x,y,x+w,y+h);}
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Headers/gl.h:2588:13: note:
'glMatrixMode' has been explicitly marked deprecated here
extern void glMatrixMode (GLenum mode) OPENGL_DEPRECATED(10.0, 10.14);
^
prova.cpp:211:5: warning: 'glLoadIdentity' is deprecated: first deprecated in macOS 10.14 - OpenGL API deprecated. (Define
GL_SILENCE_DEPRECATION to silence these warnings) [-Wdeprecated-declarations]
glLoadIdentity();
现在,我还尝试使用我通过自制软件安装的 g++-10 执行以下操作:
g++-10 -framework OpenGL -framework GLUT window.cpp prova.cpp
但我明白了
1 | #include <FL/Fl.H>
| ^~~~~~~~~
compilation terminated.
prova.cpp:9:10: fatal error: FL/gl.h: No such file or directory
9 | #include <FL/gl.h>
| ^~~~~~~~~
(这可能是问题所在)所以我将自己包含在 fltk 库中:
g++-10 -framework OpenGL -framework GLUT -I /usr/local/Cellar/fltk/1.3.5/include window.cpp prova.cpp
现在得到一个战略输出:
Undefined symbols for architecture x86_64:
"__Z12glutIdleFuncPFvvE", referenced from:
__Z14CreateMyWindowiPPc in ccApCsrQ.o
"__Z13glutSolidConeddii", referenced from:
__Z11displayConev in ccyWlxbb.o
"__Z15glutSwapBuffersv", referenced from:
__Z11displayConev in ccyWlxbb.o
"__Z16glutCreateWindowPKc", referenced from:
__Z14CreateMyWindowiPPc in ccApCsrQ.o
"__Z18glutInitWindowSizeii", referenced from: // .... and so on
这是 macOS 中的一种错误,当您不包含框架时(我认为)。
有谁知道这是哪里的问题? (这 2 个 .cpp 文件在 linux 上完美运行,所以这是 MacOs 的问题)
【问题讨论】: