我正在尝试使用 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:\Users\xxxx\AppData\Local\Temp\ccg5z97Y.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-W64 提供的 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-seh
关于c++ - 使用带有 mingw-w64 的 Allegro 5 的未定义引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55042427/