flyx / OpenGLAda

Thick Ada binding for OpenGL and GLFW
flyx.github.io/OpenGLAda/
MIT License
96 stars 13 forks source link

Examples fail with linker error on Linux #140

Closed Rodeo-McCabe closed 4 years ago

Rodeo-McCabe commented 4 years ago

Compiling any example fails with the following error:

/usr/bin/ld: -f may not be used without -shared
collect2: error: ld returned 1 exit status
gprbuild: link of colour_vertices.adb failed
gprbuild: failed command was: /usr/bin/gcc colour_vertices.o b__colour_vertices.o /home/darby/OpenGLAda/examples/superbible/vertex_colouring/obj/main_loop.o /home/darby/OpenGLAda/examples/common/libcommon.a /home/darby/OpenGLAda/lib/libOpenGLAda_Text.a /home/darby/OpenGLAda/FreeTypeAda/lib/libFreeTypeAda.a /home/darby/OpenGLAda/lib/libGlfwAda.a /home/darby/OpenGLAda/lib/libOpenGLAda.a -lfreetype -lglfw -Wl,-framework,Cocoa,-framework,IOKit -Wl,-framework,OpenGL,-framework,CoreFoundation -L/home/darby/OpenGLAda/examples/superbible/vertex_colouring/obj/ -L/home/darby/OpenGLAda/examples/superbible/vertex_colouring/obj/ -L/home/darby/OpenGLAda/examples/common/lib/ -L/home/darby/OpenGLAda/lib/ -L/home/darby/OpenGLAda/FreeTypeAda/lib/ -L/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/adalib/ -static-libgcc /usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/adalib/libgnat.a -ldl -Wl,-rpath-link,/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0//adalib -Wl,-z,origin,-rpath,$ORIGIN//obj:$ORIGIN/../..//common/lib:$ORIGIN/../../..//lib:$ORIGIN/../../..//FreeTypeAda/lib:/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/adalib -o /home/darby/OpenGLAda/examples/superbible/vertex_colouring//colour_vertices

It seems this option is being passed to the linker from the Compiler package in opengl.gpr. Removing the f there, clean building and reinstalling doesn't fix the problem. I also tried adding a Linker package in the example project file, with -shared switch, but it failed because it can't find the shared libs (probably expected). I also tried with OpenGLAda in both release and debug modes (clean building and reinstalling), but no change.

I can't find what the -f switch is even supposed to do. Any help is appreciated.

rogermc2 commented 4 years ago

From OpenGL.gpr:

package Linker is
      case Windowing_System is
         when "windows" =>
            for Linker_Options use ("-lOpenGL32", "-lGdi32");
         when "x11" =>
            for Linker_Options use ("-lGL", "-lX11");
         when "quartz" =>
            for Linker_Options use
              ("-Wl,-framework,OpenGL,-framework,CoreFoundation");
      end case;
   end Linker;

I'm wondering if the -f is coming from -framework which suggests that you have the quartz option selected which, I think, only applies to Mac systems? Possibly, you should select x11 ?

Rodeo-McCabe commented 4 years ago

Ah, so it appears the examples (and I suppose also any projects using OpenGLAda) also need be compiled with the Windowing_System scenario variable set on the command line.

To save myself the trouble I modified the default value in opengl.gpr:

   type Windowing_System_Type is
     ("windows", "x11", "quartz");
   -- has a default so that the project can be opened in GPS.
   Windowing_System : Windowing_System_Type
     := external ("Windowing_System", "x11"); -- second param here

Then I rebuilt/installed and everything works as expected. Thanks for the comment ;)