c++ - 使用带有 mingw-w64 的 Allegro 5 的未定义引用

标签 c++ linker linker-errors allegro5

我正在尝试使用 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/binC:/allegro5/includeC:/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/

相关文章:

c++ - 将我的类(class)移动到 "vc/include/"目录后出现链接错误

c++ - boost 测试链接

c++ - 模板函数在编译期间被报告为 "undefined reference"

opengl - 链接器错误: undefined reference to symbol 'glOrtho'

c - 简单的 C 内联链接器错误

c++ - 堆栈展开失败的原因

c++ - 重新打开连接的数据报套接字

java - C++ 中传递的函数参数与 Java 中传递的函数参数

c++ - #include 模板递归

c++ - 为什么模板类的静态成员不是唯一的