Closed specing closed 5 years ago
Would it be possible to have GPRBuild output -L, -l and potentially other gcc flags required for final linking an Ada library into an otherwise C/C++/whatever program that has an existing build system /= GPRBuild?
If we are talking of a static standalone library, you can use objcopy --dump-section
to extract the section .GPR.linker_options
of the partially linked file p__*
inside the archive.
I'm not sure whether or not such a static library is obtainable
It's not obtainable unless it is not a SAL. Otherwise binder always adds libgnat dependency, so even if your own code doesn't depend on libgnat, bindfile does.
Thank you, but I am having trouble finding this p* section (presumably pada_lib.o). With
library project Adalibtest is
for Library_Name use "ada_lib";
for Library_Kind use "static";
--for Library_Kind use "relocatable";
--for Library_Standalone use "encapsulated";
for Library_Standalone use "standard";
for Library_Interface use ("lib_test"); -- unit names
for Library_Dir use "lib";
for Object_Dir use "obj";
package Compiler is
for Switches ("Ada") use ("-gnata", "-gnato", "-fstack-check");
end Compiler;
end Adalibtest
there are only 2 files inside lib/libada_lib.a: b__ada_lib.o and lib_test.o as shown in objdump -s lib/libada_lib.a
output.
None of them has any section named .GPR.linker_options
.
There is also no such section when Library_Standalone and Library_Interface are commented out.
GPRBuild version is GPRBUILD GPL 2017 (19940713) (x86_64-pc-linux-gnu)
gcc version is gcc version 6.4.0
GPRBuild version is GPRBUILD GPL 2017
You need to build up-to-date gpr tools from this project.
Is the _0 suffix in p__ada_lib_0.o: file format elf64-x86-64
reliable?
I don't think so. IIRC if there's a lot of objects we may resort to linking in several stages to workaround path length limitations, in which case the number won't be 0.
Can a reliable method of determining -l and -L options be added?
Potentially such that libraries are specified with their absolute path, so as to prevent wrong libraries being picked when other -L options are added from the parent build system.
Can a reliable method of determining -l and -L options be added?
Well we told you the method that gprbuild currently uses. That section is there for a reason. What do you need to be "added"?
Thank you, I will first try using that method before complaining further.
By the way, I can only build a static library by using latest gprbuild + community2018 gcc. Using latest gprbuild + 6.4.0 (probably fsf) gcc results in:
[ 25%] Building library ada_lib...
Setup
[mkdir] object directory for project Adalibtest
[mkdir] library directory for project Adalibtest
Compile
[Ada] lib_test.adb
Build Libraries
[gprlib] ada_lib.lexch
[bind SAL] ada_lib
[Ada] b__ada_lib.adb
/usr/lib/gcc/x86_64-pc-linux-gnu/6.4.0/../../../../x86_64-pc-linux-gnu/bin/ld: -r and -pie may not be used together
collect2: error: ld returned 1 exit status
gprlib: call to linker driver /usr/bin/gcc failed
gprbuild: could not build library for project adalibtest
I don't know whether this is something that was already fixed or has to be fixed, but I'm putting it here for completeness.
Would it be possible to have GPRBuild output -L, -l and potentially other gcc flags required for final linking an Ada library into an otherwise C/C++/whatever program that has an existing build system /= GPRBuild?
Additionally, I have tested a few option combinations mentioned in https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html#stand-alone-library-projects , but was unable to obtain a static library that would have no Ada dependencies (even if no with's are added, libgnat is always there). I'm not sure whether or not such a static library is obtainable, but it would make final linking trivial.
More info: https://github.com/mosteo/ada4cmake/issues/3