I'm trying to build an Ada application that calls C code. The C code use the function sqrt
from math.h
. If I remove the call to sqrt
, the compilation and linkage work perfectly. When I try with the sqrt
call, the linker tells me undefined reference to sqrt
.
This is my gpr file:
project Struct_Interfacing is
for Languages use ("Ada", "C");
for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use ".";
for Main use ("struct_interfacing.adb");
package Compiler is
C_Switches := ("-pedantic", "-Wall", "-Werror");
for Default_Switches("C") use C_Switches;
end Compiler;
package Linker is
for Default_Switches("C") use ("-lm");
end Linker;
end Struct_Interfacing;
I thought the solution would be for Default_Switches("C") use ("-lm");
but it still doesn't work.
Your main program is in Ada,
so you should tell your compiler to link Ada with -lm
, even if the call is made from C:
package Linker is
for Default_Switches("Ada") use ("-lm");
end Linker;