1

I am trying to compile 2 .cpp files which use OpenGL and fltk on MacOs . 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 .

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 :

      (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 -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 :

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 .

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)

Jatos
  • 333
  • 2
  • 13

1 Answers1

1

Along with -I /usr/local .... option, which solves problems with include files, try adding the

-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. Also you might have to use the -lfltk in case you are linking to FLTK explicitly.

Viktor Latypov
  • 14,289
  • 3
  • 40
  • 55
  • Okay, i tried "g++-10 -framework OpenGL -framework GLUT -L /usr/local/Cellar/fltk/1.3.5/lib -I /usr/local/Cellar/fltk/1.3.5/include -lfltk window.cpp prova.cpp" and the list beginning with "Undefined symbols for architecture x86_64: " becomes very shorter but i still get it . Do you have any idea why ? – Jatos Oct 16 '20 at 11:57
  • Now you have only 32-bit libraries installed (x86, not x86_64), you have to recompile/reinstall the FLTK in x86_64 variant. – Viktor Latypov Oct 16 '20 at 12:00
  • I got the "Undefined symbols for architecture x86_64: " also before (check the output in my answer) . Now the list of Errors due to "Undefined symbols for architecture x86_64: " is much shorter : "__Z12glutIdleFuncPFvvE", referenced from: __Z14CreateMyWindowiPPc in cciPnJdO.o "__Z13glutSolidConeddii", referenced from: __Z11displayConev in cc1dj4Tw.o and so on ... – Jatos Oct 16 '20 at 12:29
  • Probably, GLUT is also old (considering only your error messages) and x86-only. Try ensuring the GLUT is correct using the 'nm/objdump' commands (run them at glut's .a or .so file. – Viktor Latypov Oct 16 '20 at 13:12
  • Glut is up to date. The problem is that on macOS you OpenGL and glut are deprecated and you need to compile them with frameworks. It is like i miss to include that framework – Jatos Oct 16 '20 at 16:48
  • Well, from this point you are pretty much on your own ) These are the precise reasons I don't do any mac programming lately. The final advice would be to switch to glfw, if it is at all possible - I had better luck with it. – Viktor Latypov Oct 16 '20 at 17:00