简体   繁体   中英

How to compile Allegro 5 program with GCC using only C programming language

stackoverflow, et. al.,

I just installed Allegro 5 on my Ubuntu machine and I see some source code for this game development tool, but I do not see specific instructions for how to compile it.

For C programs I use gcc on the terminal.

My questions are:

  • From what directory do I compile allegro5 programs?
  • What compiler options are necessary? (the normal gcc someCProgram.c -o MyProgram doesnt work)

Thank-you for reading. I have read two c books so I am not a complete noob, but I have the struggles...

All the best,

user2085446

Okay, let's put this into an answer:

If your program just consists of a single .c file, you can run gcc from the path the file is in. However, in general there's nothing wrong with invoking gcc from anywhere else as long as you get the paths right.

For linking with external libraries, you need -lmylibrary options in the compiler command, eg -lfreetype for the freetype library and so on.

Now, this can get a bit complicated when your libraries depend on other libraries etc. That's what the pkg-config tool is for.

When you look at the allegro wiki page, you will see the following sample command:

gcc [source file(s)] -o [output] `pkg-config --libs allegro-5.0`

The pkg-config bit will resolve the relevant -l options for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM