【问题标题】:Compiler detects allegro.h, but not allegro_primitives.h编译器检测到 allegro.h,但没有检测到 allegro_primitives.h
【发布时间】:2012-01-02 06:51:33
【问题描述】:

当我使用 g++ 编译我的 Allegro 5 程序时,它抱怨 undefined reference to 'al_init_primitives_addon', al_draw_filled_rectangle 和 allegro_primitives.h 中的其他此类函数。它不会抱怨 allegro.h 中的函数,例如 al_create_display

包括:

#include <allegro5/allegro.h>

#include <allegro5/allegro_primitives.h>

#include "objects.h"

#include "main.h"

编译器命令:

g++ main.cpp -o game -lallegro -I/usr/include/allegro5 -L/usr/lib/allegro5

投诉:

/tmp/ccAyQlcl.o: In function `main':
main.cpp:(.text+0xef): undefined reference to `al_init_primitives_addon'
/tmp/ccAyQlcl.o: In function `Draw()':
main.cpp:(.text+0x38c): undefined reference to `al_draw_filled_rectangle'
main.cpp:(.text+0x415): undefined reference to `al_draw_filled_rectangle'

顺便说一句,MSVC++ 编译得很好。

【问题讨论】:

    标签: c++ ubuntu g++ allegro


    【解决方案1】:

    你需要链接 allegro 和 allegro_primitives。正确的做法是:

    g++ main.cpp -o game $(pkg-config --libs 
       allegro-5.0 allegro_main-5.0 allegro_primitives-5.0)
    

    (当然,全部在一行上。)

    .pc 文件将位于 /usr/local/lib/pkgconfig 中,而这需要位于您的 PKG_CONFIG_PATH 环境变量中。

    【讨论】:

      【解决方案2】:

      您的-lallegro 不包含这些功能。如果您在系统路径中有旧库,而在 /usr/lib/allegro5 中有所需的 5.x 库,则需要在 -l 之前传递您的 -L

      【讨论】:

      • g++ main.cpp -o game -I/usr/include/allegro5 -L/usr/lib/allegro5 -lallegro?这给了我同样的错误。
      猜你喜欢
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2017-02-05
      • 2015-12-26
      • 2019-02-22
      相关资源
      最近更新 更多