使用Cmake包含Allegro库

时间:2019-05-21 20:13:18

标签: c cmake include clion allegro

我想与Allegro库一起使用。我使用homebrew和“ brew install allegro”命令来安装allegro。 现在,当我包含时,只需运行一个简单的代码,如下所示:

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

int main() {
    printf("Hello World!\n");
    return 0;

}

我收到此错误:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
     (maybe you meant: __Z16_al_mangled_mainv)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [testAllegro] Error 1
make[2]: *** [CMakeFiles/testAllegro.dir/all] Error 2
make[1]: *** [CMakeFiles/testAllegro.dir/rule] Error 2
make: *** [testAllegro] Error 2

我已将cmake用于此question的正确答案中:

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})

,仍然出现相同的错误。

0 个答案:

没有答案