I have been trying to compile a program using the allegro 5 library and writing #include<allegro5/allegro.h> to use it does not give any error, but when using any function of the library it returns an error and says that "no are defined."
Building target: AllegroTesting
Invoking: GCC C++ Linker
g++ -o "AllegroTesting" ./src/allegrotest.o ./src/test2.o
/usr/bin/ld: ./src/test2.o: en la función `main':
/home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:5: definiciones múltiples de `main'; ./src/allegrotest.o:/home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/allegrotest.cpp:6: primero se definió aquí
/usr/bin/ld: ./src/allegrotest.o: en la función `main':
/home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/allegrotest.cpp:8: referencia a `al_install_system' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/allegrotest.cpp:10: referencia a `al_create_display' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/allegrotest.cpp:12: referencia a `al_map_rgb' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/allegrotest.cpp:12: referencia a `al_clear_to_color' sin definir
/usr/bin/ld: ./src/test2.o: en la función `main':
/home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:8: referencia a `al_install_system' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:13: referencia a `al_create_display' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:19: referencia a `al_map_rgb' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:19: referencia a `al_clear_to_color' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:20: referencia a `al_flip_display' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:21: referencia a `al_rest' sin definir
/usr/bin/ld: /home/efeme/Programacion/Eclipse/AllegroTesting/Debug/../src/test2.cpp:22: referencia a `al_destroy_display' sin definir
collect2: error: ld devolvió el estado de salida 1
make: *** [makefile:58: AllegroTesting] Error 1
"make all" terminated with exit code 2. Build might be incomplete.```
The errors are from the linker because it can't find the functions it tells you.
To use a library you must tell the compiler where the .h files are to be able to access them with angular braces (
<librería.h>
) and most importantly, where to find it.In the documentation it gives you an example of how you should compile it:
If that doesn't work, you have to tell the linker to take libraries into account with the parameter
-l<librería>
. On Linux they follow the nomenclaturelib<librería>.so
. For example, if the library is calledliballegro.so
, the parameter would be-lallegro
.You also have to indicate the folder where they are located with the parameter
-L<ruta>
. For example, if they are in the folderlib/allegro
, the parameter would be-Llib/allegro
.