How to add allegro Library in Clion and CMake?
Asked Answered
K

1

5

I am trying to compile my game project using Clion IDE but I have a problem when porting allegro 5. I get this error:

main.cpp:2:10: fatal error: 'allegro/allegro.h' file not found
   #include <allegro/allegro.h>

My CMakeLists is:

cmake_minimum_required(VERSION 3.5)
project(testAllegro)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})

INCLUDE_DIRECTORIES(  /usr/local/include )
LINK_DIRECTORIES(  /usr/local/lib )

file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")

TARGET_LINK_LIBRARIES(testAllegro  ${LIBRARIES})

Just I want to ask how can I add external Library allegro to Clion?

Kalif answered 27/10, 2016 at 5:25 Comment(4)
Where is located your file allegro/allegro.h? I guess it is not in /usr/local/include. Do you have any package installed for allegro? A file called findallegro.cmake, allegroConfig.cmake, or allegro-config.cmake?Interleave
As libraries are searched under /usr/local/Cellar/allegro/, header files are located there too. So, you have to issue include_directories command with appropriate path.Adelaidaadelaide
Hi @Adelaidaadelaide I used homebrew to install allegro link and it is say " Allegro should be installed into /usr/local/lib and /usr/local/include."Kalif
If so, why do you use libraries under /usr/local/Cellar/allegro/ for link with?Adelaidaadelaide
K
13

when you install allegro using homebrew link

use this cmake to compile clion project

cmake_minimum_required(VERSION 3.5)
project(testAllegro)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(testAllegro ${SOURCE_FILES})

INCLUDE_DIRECTORIES(  /usr/local/Cellar/allegro/5.2.1.1_1/include )
LINK_DIRECTORIES(  /usr/local/Cellar/allegro/5.2.1.1_1/lib )

file(GLOB LIBRARIES "/usr/local/Cellar/allegro/5.2.1.1_1/lib/*.dylib")
message("LIBRARIES = ${LIBRARIES}")

TARGET_LINK_LIBRARIES(testAllegro  ${LIBRARIES})
Kalif answered 27/10, 2016 at 23:10 Comment(1)
it's works to me, i just change to newer version of cmake.Miniaturize

© 2022 - 2024 — McMap. All rights reserved.