[英]Using Allegro 5 library with Jetbrains CLion
我在Windows上使用MinGW(gcc / g ++)的CLion。 我花了幾個小時研究為什么我不能編譯簡單程序,因為我在鏈接所有內容時遇到了問題。
我試圖結合所有在Internet上找到的解決方案,並應用了對其他人有所幫助的更改。
這是我的main.cpp:
#include <iostream>
#include "allegro5/allegro.h"
using namespace std;
int main(int argc, char **argv) {
cout << "Hello, World!" << endl;
al_init();
return 0;
}
和CmakeList.txt:
cmake_minimum_required(VERSION 3.6)
project(untitled)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
LINK_DIRECTORIES(allegro/lib)
INCLUDE_DIRECTORIES(allegro/include)
add_executable(untitled ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(untitled allegro_acodec
allegro_audio
allegro_color
allegro_dialog
allegro_image
allegro_main
allegro_memfile
allegro_physfs
allegro_primitives
allegro_ttf
allegro_font
allegro)
file(GLOB LIBRARIES "allegro/lib/*.dll.a")
message("LIBRARIES = ${LIBRARIES}")
TARGET_LINK_LIBRARIES(untitled ${LIBRARIES})
那就是構建過程彈出的地方:
"C:\Program Files (x86)\JetBrains\CLion 2016.3.3\bin\cmake\bin\cmake.exe" --build C:\Users\Adrian\CLionProjects\untitled\cmake-build-debug --target untitled -- -j 8
-- Configuring done
LIBRARIES = C:/Users/Adrian/CLionProjects/untitled/allegro/lib/liballegro-debug.dll.a;C:/Users/Adrian/CLionProjects/untitled/allegro/lib/liballegro.dll.a;C:/Users/Adrian/CLionProjects/untitled/allegro/lib/liballegro_acodec-debug.dll.a; [... and more....]
-- Generating done
-- Build files have been written to: C:/Users/Adrian/CLionProjects/untitled/cmake-build-debug
Scanning dependencies of target untitled
[ 50%] Linking CXX executable untitled.exe
CMakeFiles\untitled.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/Adrian/CLionProjects/untitled/main.cpp:9: undefined reference to `al_install_system'
collect2.exe: error: ld returned 1 exit status
項目結構為:
└───untitled
├───.idea
├───allegro
│ ├───bin
│ ├───include
│ │ └───allegro5
│ │ ├───inline
│ │ ├───internal
│ │ ├───opengl
│ │ │ └───GLext
│ │ └───platform
│ └───lib
└───cmake-build-debug
└───CMakeFiles
├───3.6.3
│ ├───CompilerIdC
│ └───CompilerIdCXX
├───arkanoid.dir
├───CMakeTmp
├───Progress
└───untitled.dir
我已經下載了Allegro 5 x64版本,並從此處嘗試過allegro-mingw-gcc5.3.0-x64-dynamic和static: https : //github.com/liballeg/allegro5/releases
謝謝
您必須使用與構建Allegro二進制文件相同的編譯器版本。 否則,它將無法正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.