Import GLFW function to Ada

269 views Asked by At

How to import GLFW function to Ada?

Using GNAT GPS as compiler and have the following folder structure:

  • test.adb
  • test.gpr
  • bin
  • obj
  • libglfw3.a
  • lib
    • libglfw3.a

test.gpr

project test is
    for Source_Dirs use ("");
    for Main use ("test.adb");
    for Object_Dir use "obj";
    for Library_Dir use "lib";
    for Exec_Dir use "bin";
end test;

test.adb

with Interfaces.C;
with Ada.Text_IO;

procedure test is
    pragma Linker_Options("-lglfw3");
    pragma Linker_Options("-lgdi32");
    pragma Linker_Options("-lopengl32");
    function Init return Interfaces.C.int;
    pragma Import(C,Init,"glfwInit");
    success : Interfaces.C.int;
begin
   success := Init;
   Ada.Text_IO.Put_Line(success'Img);
end test;

Compiling with gprbuild -P test.gpr and outputs:

p:/gnat/2014/bin/../libexec/gcc/i686-pc-mingw32/4.7.4/ld.exe: cannot find -lglfw3

So I was thinking when gdi32, winmm, opengl32 is found is because they are already installed on my PC. I don't know if they are needed, but just to be on the safe side. The glfw3 lib is not found so I don't know if I'm using the Linker_Option the right way or where to put the libglfw3.a file. Is there a good way to link to c libraries?

1

There are 1 answers

1
Frenchman On
pragma Linker_Options("-lglfw3dll");

Is a bad method, It should be like below:

pragma Linker_Options("-lglfw3"); 

To tell the linker to use library file libglfw3.a

To check libglfw3.a is in the object path used by GNAT, type the command

gnatls -v

Complete Ada binding to both GLFW2 and GLFW3 with GPR project files are available at OpenGLAda currently at Github.