简体   繁体   English

为什么即使使用 -L 和 -I 命令,object 文件也没有与 allegro 库链接?

[英]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.

相关问题 为什么 C++ 链接器在构建过程中需要库文件,即使我是动态链接的? - Why does the C++ linker require the library files during a build, even though I am dynamically linking? 使用physfs时allegro 5写入文件 - allegro 5 writing files when using physfs 与静态库链接与在 C++ 中使用目标文件时的不同行为 - different behavior when linking with static library vs using object files in C++ 将msvc中的Allegro 4.4库链接到项目 - Linking Allegro 4.4 library in msvc to a project 为什么即使在包含math.h并使用-lm链接到数学库后也得到“未定义符号:.sqrtf”的原因 - why I am getting “Undefined symbol: .sqrtf” even after Including math.h and linking to math library using -lm 使用g ++编译器(Ubuntu)将Allegro库链接到C ++应用程序 - Linking the Allegro library to a C++ application using the g++ compiler (Ubuntu) 将Allegro 5库与Jetbrains CLion一起使用 - Using Allegro 5 library with Jetbrains CLion 为什么我的共享库在使用CMake时无法正确链接? - Why is my shared library not linking correctly when using CMake? 即使我用 -L 指定了它的位置,链接器也找不到库 - The linker can't find a library even when i have specified it's location with -L 为什么即使使用 -cudart static 编译,库用户仍然需要链接到 cuda 运行时 - Why is linking to cuda runtime still necessary for library user even when compiling with -cudart static
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM