Search code examples
c++macoscmakeclionallegro5

allegro5 project in CLion, ld: library not found error


I'm making a C++ and allegro5 project for university. I compiled allegro library and it's working well in Xcode for example. But I wanted to do my project in CLion and as soon as try to build project including allegro it throws an error:

ld: library not found for -lallegro_acodec
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [TEST1] Error 1
make[1]: *** [CMakeFiles/TEST1.dir/all] Error 2
make: *** [all] Error 2

CMakeLists.txt:

cmake_minimum_required(VERSION 3.3)
project(TEST1)

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

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

INCLUDE_DIRECTORIES( /usr/local/Cellar/allegro/5.0.11/include )

LINK_DIRECTORIES( /usr/local/Cellar/allegro/5.0.11/lib )

TARGET_LINK_LIBRARIES(TEST1
        allegro_acodec
        allegro_audio
        allegro_color
        allegro_dialog
        allegro_image
        allegro_main
        allegro_memfile
        allegro_physfs
        allegro_primitives
        allegro_ttf
        allegro_font
        allegro)

main.cpp:

#include <iostream>
#include <allegro5/allegro.h>

using namespace std;

int main(int argc, char **argv) {

    al_init();

    return 0;
}

I'm working on OSX 10.11. I could not find solution for my problem. I konw that allegro and CLion are not that popular. Can anyone help me what that error means?


Solution

  • You should issue link_directories before add_executable.

    From the documentation about link_directories:

    The command will apply only to targets created after it is called.