[英]Why object files are not linking with the allegro library even when using -L and -I commands?
I'm using vs code and trying to link with allegro.我正在使用 vs 代码并尝试与 allegro 链接。 I've little knowledge about.json files so i avoid them.
我对.json 文件知之甚少,所以我避免使用它们。 This is the sample code i'm trying to run:
这是我试图运行的示例代码:
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
int main(int argc, char **argv)
{
al_init();
al_init_font_addon();
ALLEGRO_DISPLAY* display = al_create_display(800, 600);
ALLEGRO_FONT* font = al_create_builtin_font();
al_clear_to_color(al_map_rgb(0, 0, 0));
al_draw_text(font, al_map_rgb(255, 255, 255), 400, 300, ALLEGRO_ALIGN_CENTER, "Welcome to Allegro!");
al_flip_display();
al_rest(5.0);
al_destroy_font(font);
al_destroy_display(display);
return 0;
}
by using the cmd command:通过使用 cmd 命令:
g++ -o test.exe main.cpp -IE:\ImportantSoftwares\allegro\include -LE:\ImportantSoftwares\allegro\lib -lallegro_monolith
Im getting following error:我收到以下错误:
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x3a): undefined reference to `al_install_system'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x3f): undefined reference to `al_init_font_addon'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x53): undefined reference to `al_create_display'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x5b): undefined reference to `al_create_builtin_font'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x81): undefined reference to `al_map_rgb'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0xa4): undefined reference to `al_clear_to_color'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0xc7): undefined reference to `al_map_rgb'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x113): undefined reference to `al_draw_text'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x118): undefined reference to `al_flip_display'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x126): undefined reference to `al_rest'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x131): undefined reference to `al_destroy_font'
C:\Users\SHAO~1\AppData\Local\Temp/cccXEAJj.o:main.cpp:(.text+0x13c): undefined reference to `al_destroy_display'
collect2: ld returned 1 exit status
I have also tried to link allegro with codeblocks step by step described in this video: https://youtu.be/xH8mpOfRGxE我还尝试将 allegro 与此视频中描述的代码块逐步链接: https://youtu.be/xH8mpOfRGxE
But im getting same error但我得到同样的错误
EDIT:编辑:
I've changed above command to:我已将上述命令更改为:
g++ main.cpp -o test.exe -IE:/ImportantSoftwares/allegro/include -LE:/ImportantSoftwares/allegro/lib -lallegro_monolith-debug.dll -lallegro_monolith.dll
i've also tried removing.dll in above command like:我也试过在上面的命令中删除.dll,如:
g++ main.cpp -o test.exe -IE:/ImportantSoftwares/allegro/include -LE:/ImportantSoftwares/allegro/lib -lallegro_monolith-debug -lallegro_monolith
but im getting same error但我得到同样的错误
The problem is fixed.问题已解决。 I found out that allegro libraries was not compatible with my linker.
我发现 allegro 库与我的 linker 不兼容。 I've updated allegro libraries and it's working fine now.
我已经更新了 allegro 库,现在运行良好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.