【问题标题】:Undefined reference using Allegro 5 with mingw-w64使用 Allegro 5 和 mingw-w64 的未定义引用
【发布时间】:2019-07-29 06:13:06
【问题描述】:

我正在尝试使用 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-x86_64-w64-mingw32-gcc-8.2.1-posix-seh-static-5.2.5.0.zip)下载了 Allegro 5 的 Windows 二进制文件,并将文件解压缩到 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 是否足够?

【问题讨论】:

    标签: c++ linker linker-errors allegro5


    【解决方案1】:

    这个:

    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

    【讨论】:

    • 我花时间了解了所有这些版本值的含义。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 2020-06-27
    • 2016-10-06
    • 2014-02-04
    • 1970-01-01
    • 2012-10-06
    相关资源
    最近更新 更多