'ranlib Error using Alire and GNAT with ASFML
i am learning how to use Alire using the Ada binding to SFML which is ASFML. So far I have downloaded and installed ASFML using Alire and have successfully imported it into my test project. When I go to compile it, it does compile and bind but gets stuck on the Linker phase.
Here is the error:
gprbuild -d -PC:\Users\Amynu\testproj\testproj.gpr -XASFML_BUILD_MODE=optimize -XASFML_CONTRACTS=enabled -XASFML_STYLE_CHECKS=enabled -XASFML_RUNTIME_CHECKS=enabled -XASFML_COMPILE_CHECKS=enabled -XOS=Windows_NT -XTESTPROJ_BUILD_MODE=optimize -XTESTPROJ_CONTRACTS=disabled -XTESTPROJ_STYLE_CHECKS=disabled -XTESTPROJ_RUNTIME_CHECKS=disabled -XTESTPROJ_COMPILE_CHECKS=disabled
Compile
[Ada] testproj.adb
Bind
[gprbind] testproj.bexch
[Ada] testproj.ali
Link
[link] testproj.adb
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: C:\Users\Amynu\testproj\alire\cache\dependencies\asfml_2.5.2_b775db19\lib\libasfml.a: error adding symbols: archive has no index; run ranlib to add one
collect2.exe: error: ld returned 1 exit status
gprbuild: link of testproj.adb failed
I have absolutely no idea what a "ranlib" is, I searched Alire but it's not a known crate or a library. I tried various options in Alire such as
alr with libranlib
and
alr get ranlib
To no avail. Is it an option within GNAT's command line? I did look into the GPR file for the project and that all looks alright. One the GPR's being auto generated by Alire when I build the project with
alr init --bin testproj
alr cd testproj
alr with libasfml
alr build
I did a Google search and found a lot of solutions connected to Unix and IBM(?) something about ranlib being outdated as most compilers use "rm" now? I couldn't find a solution to GNAT flagging the same error.
Am I just using an outdated audio library?
Thanks in advance for any help :)
Solution 1:[1]
Thank you guys! That solved the problem. Now I am stuck with a loads of "undefined references to..." I actually went through all the source files and got rid of all the warnings by addIng Constant to most variable names. I am guessing it's looking for a dependency that is missing?
Build Libraries [gprlib] asfml.lexch [link library] libasfml.dll c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: C:\Users\Amynu\testproj\alire\cache\dependencies\asfml_2.5.2_b775db19\obj\sf-audio-music.o:sf-audio-music.adb:(.text+0x32): undefined reference to `sfMusic_createFromFile'
And about 15 lines under that with the same error type. After looking into it, I had a look a the lines of code the error were referring to and found the errors are referencing what look like external files? Is their a part of ASFML that didn't download with the library?
Solution 2:[2]
I scoured the code for the first linker error and found line it's referring to.
with Interfaces.C.Strings;
package body Sf.Audio.Music is
use Interfaces.C.Strings;
--//////////////////////////////////////////////////////////
--/ Create a new music and load it from a file
--/
--/ @param Filename Path of the music file to open
--/
--/ @return A new sfMusic object (NULL if failed)
--/
--//////////////////////////////////////////////////////////
function CreateFromFile (Filename : String) return sfMusic_Ptr is
function Internal (Filename : chars_ptr) return sfMusic_Ptr;
pragma Import (C, Internal, "sfMusic_createFromFile");
Temp : chars_ptr := New_String (Filename);
R : sfMusic_Ptr := Internal (Temp);
begin
Free (Temp);
return R;
end CreateFromFile;
I cannot find the file it's trying to reference anywhere in the ASFML library. Was it left out?
So far, I have managed to successfully build ASFML in Alire with
alr get asfml
cd asfml
alr build asfml
This worked fine. Then I successfully imported into my project with
cd myproj
alr myproj with asfml
Again, do problems. Then I attempted to build it (after correcting the ranlib error) and I got the same load of linker errors. I don't understand why, as I successfully built the asfml library before I imported it wit Alire. Is it just a file I am missing, or do I have to explicitly tell the linker where the asfml file is?
Some of the errors.
Compile
[Ada] alicegame.adb
Build Libraries
[gprlib] asfml.lexch
[link library] libasfml.dll
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: C:\Users\Amynu\alicegame\alire\cache\dependencies\asfml_2.5.2_b775db19\obj\sf-audio-music.o:sf-audio-music.adb:(.text+0x32): undefined reference to `sfMusic_createFromFile'
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: C:\Users\Amynu\alicegame\alire\cache\dependencies\asfml_2.5.2_b775db19\obj\sf-audio-soundbuffer.o:sf-audio-soundbuffer.adb:(.text+0x22): undefined reference to `sfSoundBuffer_createFromFile'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ada Lovelace |
Solution 2 | Ada Lovelace |