我正在尝试使用 mingw-w64 在 Windows 10 上编译 Allegro 5 程序。
-
我已经安装了 mingw-w64。
g++ --version
的输出为:g++.exe (i686-posix-dwarf-rev2, Built by MinGW-W64 project) 7.1.0 Copyright (C) 2017 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
我从 https://github.com/liballeg/allegro5/releases 下载了 Allegro 5 的 Windows 二进制文件(文件:
allegro-x86_64-w64-mingw32-gcc-8.2.1-posix-seh-static-5.2.5.0.zip
年),并将文件解压缩到C:/allegro5
所以现在我有C:/allegro5/bin
、C:/allegro5/include
、C:/allegro5/lib
。 -
一个小型测试程序:
#include <stdio.h> #include <allegro5/allegro.h> int main(int argc, char **argv) { al_init(); return 0; }
-
最后是我运行编译的命令:
g++ test.cpp -I"C:/allegro5/include" -L"C:/allegro5/lib" -lallegro
(C:/allegro5/lib
下有一个名为liballegro.dll.a
的lib文件)
但是链接时存在一些问题:
C:UsersxxxxAppDataLocalTempccg5z97Y.o:test.cpp:(.text+0x1e): undefined reference to `al_install_system'
collect2.exe: error: ld returned 1 exit status
A) 可能是什么原因?
B) 我应该怎么做才能以静态方式编译?将-lallegro
更改为-lallegro-static
就足够了吗?
这个:
g++.exe (i686-posix-dwarf-rev2, Built by MinGW-W64 project) 7.1.0
是MinGW-W34提供的32位GCC变体之一。您正在尝试链接 它使用以下版本中提供的 64 位库生成的 32 位代码:
allegro-x86_64-w64-mingw32-gcc-8.2.1-posix-seh-static-5.2.5.0.zip
这是行不通的。将编译器替换为适当的 64 位变体 x86_64-posix-she