• Create Account

# Allegro and CMake: So close, but won't compile

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1AniMerrill  Members   -  Reputation: 203

Like
1Likes
Like

Posted 03 March 2013 - 01:46 PM

EDIT: So eventually figured out the problem, posted the answer down below.

So over the last week I've been pulling my hair out trying to figure out Ubuntu and how to compile using a terminal instead of an IDE and even somewhat taught myself how to use CMake so hopefully my game can be multiplatform. I successfully made and ran my first CMake file, but then when I went to "make" the file it created, it wouldn't compile.

The error it threw me was basically "allegro5/allegro.h" doesn't exist as a directory when it gets to my first cpp file. I'm sure this is either A) some error I made in the CMakeLists.txt file or B) some fundamental misunderstanding I have about Linux... or something. So sorry if this is a repost, I just don't have enough knowledge about either of these things to know what to search for on Google.

CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)
project(game)
set(CMAKE_VERBOSE_MAKEFILE on)

#The version number
set(game_VERSION_MAJOR 0)
set(game_VERSION_MINOR 1)

set(game_SRCS SpriteSheet.cpp AnimationSet.cpp Map.cpp Character.cpp Main.cpp)

add_executable(game ${game_SRCS}) #Include Allegro include_directories(/home/username/Documents/allegro-5.0.9/build/include) #=============== link_directories(/home/username/Documents/allegro-5.0.9/build/lib) #=============== target_link_libraries(game liballegro.so)  The line that the error refers to is SpriteSheet.cpp where I've put #include <allegro5/allegro.h>. I almost forgot to mention that this is the first time I've compiled an external library, like Allegro, from source... so I may have screwed something up there. I've never seen a .so file in my life, but I'm going to just assume its a Linux thing. Also, if it matters at all, I'm on Ubuntu 12.10 and using Allegro 5.0.9. Thanks in advanced for any help. Edited by AniMerrill, 04 March 2013 - 09:39 PM. AniMerrill, a.k.a. Ethan Merrill Sponsor: ### #2adt7 Members - Reputation: 425 Like 0Likes Like Posted 04 March 2013 - 08:35 AM Some potentially "stupid" questions, but: • Do the paths "/home/username/Documents/allegro-5.0.9/build/include" and "/home/username/Documents/allegro-5.0.9/build/lib" exist? (I assume in your actual file "username" is replaced with your actual user name.) • Is there an "allegro5" subdirectory under "/home/username/Documents/allegro-5.0.9/build/include"? • Is liballegro.so in your "/home/username/Documents/allegro-5.0.9/build/lib" directory? ### #3AniMerrill Members - Reputation: 203 Like 0Likes Like Posted 04 March 2013 - 10:34 AM Some potentially "stupid" questions, but: • Do the paths "/home/username/Documents/allegro-5.0.9/build/include" and "/home/username/Documents/allegro-5.0.9/build/lib" exist? (I assume in your actual file "username" is replaced with your actual user name.) • Is there an "allegro5" subdirectory under "/home/username/Documents/allegro-5.0.9/build/include"? • Is liballegro.so in your "/home/username/Documents/allegro-5.0.9/build/lib" directory? No not stupid questions at all, since these are things I could have probably overlooked if you hadn't pointed them out. 1) Yes "username" is my username, not just username. Unless the Ubuntu file system works in a weird way I don't know, those two folders should be exactly correct. I can direct the terminal from the root folder using that address anyway. Also "build/include" and "build/lib" are the build folders for when I ran CMake on the Allegro 5 library. 2) There is an "allegro5" folder in that include directory, um... but I just realized that there is no "allegro.h" in it even though it exists in the "/home/username/Documents/allegro-5.0.9/include/allegro5" directory. I can only assume I either broke the CMake run or the make compilation for the library then... I was just following along what little tutorials I could find on the subject and hadn't really thought to check. 3) Yes, "liballegro.so" exists in that lib directory. Um, I notice under the build lib directory where "liballegro.so" is there's a folder called "Headers" which pretty much looks exactly like the pre-build include folder. Is it possible I have to link to this or is there just something fundamental I'm not understanding here? I know when you do straight command line compilation, this tutorial says you only need to do this: $ g++ [source file(s)] -o [output] pkg-config --libs allegro-5.0.

But a) I don't completely understand this either (at least the pkg-config --libs allegro-5.0. which doesn't seem to point to any real file) and b) I don't know how to convert this into a CMake command.

Edited by AniMerrill, 04 March 2013 - 10:34 AM.

AniMerrill, a.k.a. Ethan Merrill

### #4AniMerrill  Members   -  Reputation: 203

Like
0Likes
Like

Posted 04 March 2013 - 09:33 PM

Well I eventually figured it out, so I'm going to post it up here for any noobies of the future that make a similar mistake. Here's the makefile that I ended up with to get my program to compile successfully on Ubuntu 12.10.
cmake_minimum_required(VERSION 2.6)
project(game)
set(CMAKE_VERBOSE_MAKEFILE on)

#The version number
set(game_VERSION_MAJOR 0)
set(game_VERSION_MINOR 1)

set(game_SRCS SpriteSheet.cpp AnimationSet.cpp Map.cpp Character.cpp Main.cpp)

add_executable(game ${game_SRCS}) #Include Allegro include_directories(/home/username/Documents/allegro-5.0.9/build/include) include_directories(/home/username/Documents/allegro-5.0.9/build/lib/Headers) link_directories(/home/username/Documents/allegro-5.0.9/build/lib) #connect all the libraries you need set(game_LIBS liballegro.so liballegro_dialog.so liballegro_image.so) target_link_libraries(game${game_LIBS})

Note: I transferred this project over from Visual Studio so currently I only NEEDED the base allegro, native dialog, and image libraries because that's all the code used so far.

So first mistake I made: the reason I was getting that error about <allegro5/allegro.h> is because apparently filenames work with \ not /. So simply changing all my <allegro5/whatever.h> to <allegro5\whatever.h> fixed that problem.

The next problem is that I needed to either include_directories() where the "Headers" was. Which is odd, because that's not how it works when working with Microsoft development. From what I saw, the build include folder only has configuration files in it while the Headers file in the build lib folder has what's in a normal windows include folder. I can only assume the other work around would be to alter all my #include statements inside my code to "Headers/allegro5/allegro_whatever.h" but that seems to wordy for what I wanted.

Idk, anyone else who wants to toss two cents in can but for now I'm just happy I got this stupid thing to compile.

AniMerrill, a.k.a. Ethan Merrill

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS