[英]Compiling a file which uses fltk and OpenGL with g++ gives error on MacOs
I am trying to compile 2 .cpp files which use OpenGL and fltk on MacOs .我正在尝试编译 2 个在 MacOs 上使用 OpenGL 和 fltk 的 .cpp 文件。 On a device using linux (Fedora ) I use the command : g++-9 -std=c++17 window.cpp prova.cpp -o test -lfltk -lGL -lglut -lGLU -lfltk_gl
and everything works well .在使用 linux (Fedora) 的设备上,我使用命令: g++-9 -std=c++17 window.cpp prova.cpp -o test -lfltk -lGL -lglut -lGLU -lfltk_gl
一切正常。
On Mac_Os terminal instead I try with : g++ -framework GLUT -framework OpenGL -lGLU -lfltk -lglut -lGL -framework Cocoa window.cpp prova.cpp
and I get an infinite number of errors (which i don't get on linux) and warnings such :在 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();
Now, I also tried to use the g++-10 which i installed via homebrew doing the following :现在,我还尝试使用通过自制软件安装的 g++-10 执行以下操作:
g++-10 -framework OpenGL -framework GLUT window.cpp prova.cpp
but i get但我明白了
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>
| ^~~~~~~~~
(and this could be the problem) so I included myself the fltk lib : (这可能是问题所在)所以我将自己包含在 fltk lib 中:
g++-10 -framework OpenGL -framework GLUT -I /usr/local/Cellar/fltk/1.3.5/include window.cpp prova.cpp
now getting a strage output :现在得到一个奇怪的输出:
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
This is a kind of error in macOS that you get (i think) when you don't include a framework .这是 macOS 中的一种错误,当您不包含 framework 时(我认为)。
Is there anyone who knows which is the problem in this ?有没有人知道这是什么问题? (the 2 .cpp files perfectly work on linux so it is a problem of MacOs) (2个.cpp文件在linux上完美运行,所以这是MacOs的问题)
Along with -I /usr/local ....
option, which solves problems with include files , try adding the与-I /usr/local ....
选项一起解决包含文件的问题,尝试添加
-L /usr/local/Cellar/fltk/1.3.5/lib (look up the exact folder name with .a and .so files)
optional which tells the linker from g++-10 package to look for library file itself in the directory. optional 告诉 g++-10 包中的链接器在目录中查找库文件本身。 Also you might have to use the -lfltk
in case you are linking to FLTK explicitly.此外,如果您明确链接到 FLTK,您可能必须使用-lfltk
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.