|
Compile and link allegro5 avoiding installation. |
On1gh1r1
Member #16,028
July 2015
|
Hi all, i created a game using Allegro5 in a Linux environment, so i compiled it using this makefile: 1CFLAGS = -Wall -c
2EFLAGS =
3EOPTION = `pkg-config --cflags --libs allegro-5.0 allegro_primitives-5.0 allegro_font-5.0 allegro_audio-5.0 allegro_ttf-5.0 allegro_image-5.0 allegro_acodec-5.0` -lm
4OBJFOLD = obj
5SOURCE = #The list of the source files.
6OBJECT = #The list of the object files.
7EXC = Prova
8
9all: $(SOURCE) $(EXC)
10
11$(EXC): $(OBJECT)
12 gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(EOPTION)
13
14$(OBJFOLD)/%.o: %.c
15 gcc $(CFLAGS) $< -o $@
16
17$(OBJFOLD)/%.o: libraries/%.c
18 gcc $(CFLAGS) $< -o $@
And it works fine 'cause i installed Allegro5 following the Wiki's guide, but i want to write a makefile that compile the game in every Linux environment, so i can post my project and let other people try it. So, can someone tell me if it possible to write a makefile to compile Allegro5 without installing it? And, maybe, can someone help me to write it?? |
Elias
Member #358
May 2000
|
Use the INSTALL_PREFIX cmake option. Call this little script from your Makefile: git clone https://github.com/liballeg/allegro5.git mkdir build-allegro5 cd build-allegro5 cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 ../allegro5 make -j4 make install First line of course only if you don't distribute Allegro5 yourself. You can leave out the WANT_MONOLITH and SHARED options if you prefer something else. Now this will work in your game's main Makefile (assuming it's in the same directory you ran the script from): PKG_CONFIG_PATH=build-allegro5/install/lib/pkgconfig pkg-config allegro_monolith-static-5 --libs --cflags For me this outputs: -I/home/elias/prog/allegro/tmp/build-allegro5/install/include -L/home/elias/prog/allegro/tmp/build-allegro5/install/lib -lallegro_monolith-static -lm -lpthread -lSM -lICE -lX11 -lXext -lXcursor -lXi -lXinerama -lXrandr -lGLU -lGL -lSM -lICE -lX11 -lXext -lpng -lz -ljpeg -lpulse-simple -lpulse -lasound -lopenal -lFLAC -logg -ldumb -lvorbisfile -lvorbis -logg -lfreetype -lz -lphysfs -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lgthread-2.0 -lglib-2.0 -ltheoradec -logg -lvorbisfile -lvorbis -logg
-- |
On1gh1r1
Member #16,028
July 2015
|
Oh, very very thanks Elias, now my makefile seems like (i already include allegro5 folder in my project): 1CFLAGS = -Wall -c
2EFLAGS =
3EOPTION = -Ibuild-allegro5/install/include -Lbuild-allegro5/install/lib -lallegro_monolith-static -lm -lpthread -lSM -lICE -lX11 -lXext -lXcursor -lXi -lXinerama -lXrandr -lGLU -lGL -lSM -lICE -lX11 -lXext -lpng -lz -ljpeg -lpulse-simple -lpulse -lasound -lopenal -lFLAC -logg -ldumb -lvorbisfile -lvorbis -logg -lfreetype -lz -lphysfs -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lgthread-2.0 -lglib-2.0 -ltheoradec -logg -lvorbisfile -lvorbis -logg
4OBJFOLD = obj
5SOURCE = #List of source files.
6OBJECT = #List of object files.
7ALLEGRO = build-allegro5
8EXC = Prova
9
10all: SCRIPT $(SOURCE) $(EXC)
11
12SCRIPT:
13 git clone https://github.com/liballeg/allegro5.git; \
14 mkdir $(ALLEGRO); \
15 cd $(ALLEGRO); \
16 cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 ../allegro5; \
17 make -j4; \
18 make install; \
19 cd ..; \
20 PKG_CONFIG_PATH=build-allegro5/install/lib/pkgconfig pkg-config allegro_monolith-static-5 --libs --cflags
21
22$(EXC): $(OBJECT)
23 gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(EOPTION)
24
25$(OBJFOLD)/%.o: %.c
26 gcc $(CFLAGS) $< -o $@
27
28$(OBJFOLD)/%.o: libraries/%.c
29 gcc $(CFLAGS) $< -o $@
Now i have another problem: the compiler doesn't find the theoradec library, so i cannot try if the makefile works. But obviously i cannot install all the depending libraries, so what i can do? Where do you find what libraries are necessary? |
Elias
Member #358
May 2000
|
I would have left it as an external script and just call from the Makefile - this is the best I got it to work from within a Makefile: ALLEGRO_GIT = https://github.com/liballeg/allegro5.git ALLEGRO_OPTIONS = `pkg-config allegro_monolith-static-5 --libs --cflags --static` export PKG_CONFIG_PATH = build-allegro5/install/tlib/pkgconfig TEST: ALLEGRO echo $(ALLEGRO_OPTIONS) ALLEGRO: allegro5 cd allegro5; git pull mkdir -p build-allegro5 cd build-allegro5;\ cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 ../allegro5;\ make -j4;\ make install allegro5: git clone ${ALLEGRO_GIT} As for the theoradec issue, I don't know. What is the exact command that's executed and causes the error, and what is the full error message? -- |
On1gh1r1
Member #16,028
July 2015
|
Nono, my script works fine, the problem comes when i try to link all the object files to create the exe file. The pkg-config command have too much libraries, and one of them (-ltheoradec) was not found. The error message was: /usr/bin/ld: impossible to find -ltheoradec collect2: error: ld returned 1 exit status
|
Elias
Member #358
May 2000
|
Hm, try passing -D WANT_VIDEO=0 to cmake and see if the error disappears. -- |
On1gh1r1
Member #16,028
July 2015
|
Nope,i tried but the error is the same, i also try to delete -ltheoradec from pfg-config and the compilation works fine, but when i run my program, allegro_init() function failed. Now i try to run the makefile on another pc, hoping it will work. |
Elias
Member #358
May 2000
|
I see another problem, do this: ALLEGRO_CFLAGS = `pkg-config allegro_monolith-static-5 --cflags --static` ALLEGRO_LIBS = `pkg-config allegro_monolith-static-5 --libs --static` And then later: $(EXC): $(OBJECT) gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(ALLEGRO_LIBS) $(OBJFOLD)/%.o: %.c gcc $(CFLAGS) $(ALLEGRO_CFLAGS) $< -o $@ Basically you need different flags for compiling and linking. -- |
On1gh1r1
Member #16,028
July 2015
|
I follow your advice, but a strange thing happened: My-Linux-PC$ PKG_CONFIG_PATH=build-allegro5/install/lib/pkgconfig pkg-config allegro_monolith-static-5 --libs --cflags -Imylonghomepath/build-allegro5/install/include -Lmylonghomepath/build-allegro5/install/lib\ -lallegro_monolith-static And when i try to compile using `pkg-config allegro_monolith-static-5 --libs --static` option, it gave me this error: Package allegro_monolith-static-5 was not found in the pkg-config search path. Perhaps you should add the directory containing `allegro_monolith-static-5.pc' to the PKG_CONFIG_PATH environment variable No package 'allegro_monolith-static-5' found
Like the PKG_CONFIG_PATH was not setted D= |
Elias
Member #358
May 2000
|
Inside the makefile, use the export command to set the environment variable: export PKG_CONFIG_PATH = build-allegro5/install/lib/pkgconfig
-- |
On1gh1r1
Member #16,028
July 2015
|
I forgot to tell you i solved the problem doing exactly what you say, but when i try to compile, it return 'Undefined reference to "any allegro function"', it think it's impossible to compile this way allegro programs =/ |
Elias
Member #358
May 2000
|
What does your complete script look like now? -- |
On1gh1r1
Member #16,028
July 2015
|
1CFLAGS = `pkg-config allegro_monolith-static-5 --cflags --static`
2EFLAGS =
3EOPTION = `pkg-config allegro_monolith-static-5 --libs --static`
4OBJFOLD = obj
5SOURCE = #my long source list.
6OBJECT = #my long object list.
7ALLEGRO = build-allegro5
8EXC = Prova
9
10all: SCRIPT $(SOURCE) $(EXC)
11
12SCRIPT:
13 git clone https://github.com/liballeg/allegro5.git; \
14 mkdir $(ALLEGRO); \
15 cd $(ALLEGRO); \
16 cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 -D WANT_VIDEO=0 ../allegro5; \
17 make -j4; \
18 make install; \
19 cd ..
20
21$(EXC): $(OBJECT)
22 export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"; \
23 gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(EOPTION)
24
25$(OBJFOLD)/%.o: %.c
26 export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"; \
27 gcc $(CFLAGS) $< -o $@
28
29$(OBJFOLD)/%.o: libraries/%.c
30 export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"; \
31 gcc $(CFLAGS) $< -o $@
Main.c: undefined reference to "al_init()" For all allegro function =) |
Elias
Member #358
May 2000
|
Are you certain your export commands work? For me it only works if I have the export at the top of the Makefile, like in my version. Other than that I have no idea - can you show the complete make output? Maybe there's some other clues there... -- |
On1gh1r1
Member #16,028
July 2015
|
It works 'cause it gives me no "not found" error. Anyway, this is the errors: export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"; \ gcc `pkg-config allegro_monolith-static-5 --cflags --static` Main.c -o obj/Main.o /tmp/ccVEllH6.o: in function "main": Main.c:(.text+0x19): undefined reference to "al_install_system" Main.c:(.text+0x96): undefined reference to "al_set_window_title" Main.c:(.text+0xa3): undefined reference to "al_hide_mouse_cursor" /tmp/ccVEllH6.o: in function "create_display": Main.c:(.text+0xc9): undefined reference to "al_create_display" ...... and it continues for all the allegro functions. If i run this script 1SCRIPT:
2 git clone https://github.com/liballeg/allegro5.git; \
3 mkdir $(ALLEGRO); \
4 cd $(ALLEGRO); \
5 cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 -D WANT_VIDEO=0 ../allegro5; \
6 make -j4; \
7 make install; \
8 cd ..; \
9 export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"
10
11$(EXC): $(OBJECT)
12 gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(EOPTION)
13
14$(OBJFOLD)/%.o: %.c
15 gcc $(CFLAGS) $< -o $@
16
17$(OBJFOLD)/%.o: libraries/%.c
18 gcc $(CFLAGS) $< -o $@
it gives me: gcc `pkg-config allegro_monolith-static-5 --cflags --static` Main.c -o obj/Main.o Package allegro_monolith-static-5 was not found in the pkg-config search path. Perhaps you should add the directory containing `allegro_monolith-static-5.pc' to the PKG_CONFIG_PATH environment variable No package 'allegro_monolith-static-5' found /tmp/ccVEllH6.o: in function "main": Main.c:(.text+0x19): undefined reference to "al_install_system" Main.c:(.text+0x96): undefined reference to "al_set_window_title" Main.c:(.text+0xa3): undefined reference to "al_hide_mouse_cursor" /tmp/ccVEllH6.o: in function "create_display": Main.c:(.text+0xc9): undefined reference to "al_create_display" ...... I search over and over the web, but apparently no one asks about my same problem =/ |
Elias
Member #358
May 2000
|
On1gh1r1 said: Package allegro_monolith-static-5 was not found in the pkg-config search path. That means pkg-config did not work, try with the export like I have it. [edit:] Oh, I see, you didn't get that before... should not matter then. (But in my version, you need to put it at the top, not inside any rule.) Anyway, as long as that error isn't there either version apparently works. [edit2:] Also, the parameter order is wrong, pkg-config --libs has to come after the sources. -- |
On1gh1r1
Member #16,028
July 2015
|
Nothing is changes. |
Elias
Member #358
May 2000
|
Hm, there's no reason it shouldn't work, it does here. Try this, just typing in a console: export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig" gcc Main.c -o obj/Main.o `pkg-config allegro_monolith-static-5 --cflags --static` Does it also given an error about not finding Allegro functions? -- |
On1gh1r1
Member #16,028
July 2015
|
The same. Sorry Elias, i just make you waste your time =(. |
Elias
Member #358
May 2000
|
Oh, true, try adding -DALLEGRO_STATICLINK to the options. -- |
On1gh1r1
Member #16,028
July 2015
|
EDIT: I finally solved this way (and i hope it will work): 1CFLAGS = -Ibuild-allegro5/install/include
2EFLAGS =
3EOPTION = -Ibuild-allegro5/install/include -Lbuild-allegro5/install/lib `pkg-config allegro_monolith-static-5 --libs --static` -DALLEGRO_STATICLINK
4OBJFOLD = obj
5SOURCE = #Sources list.
6OBJECT = #Obj list.
7ALLEGRO = build-allegro5
8EXC = Game
9
10all: SCRIPT $(SOURCE) $(EXC)
11
12SCRIPT:
13 mkdir $(ALLEGRO); \
14 cd $(ALLEGRO); \
15 cmake -D CMAKE_INSTALL_PREFIX=install -D WANT_MONOLITH=1 -D WANT_DOCS=0 -D WANT_EXAMPLES=0 -D WANT_DEMO=0 -D SHARED=0 -D WANT_VIDEO=0 ../allegro5; \
16 make -j4; \
17 make install; \
18 cd ..
19
20$(EXC): $(OBJECT)
21 export PKG_CONFIG_PATH="build-allegro5/install/lib/pkgconfig"; \
22 gcc $(EFLAGS) -o $(EXC) $(OBJECT) $(EOPTION)
23
24$(OBJFOLD)/%.o: %.c
25 gcc -Wall -c $< -o $@ $(CFLAGS)
26
27$(OBJFOLD)/%.o: libraries/%.c
28 gcc -Wall -c $< -o $@ $(CFLAGS)
Thanks you so much for patience =) |
|