Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将allegro5库链接到C++;项目 我有一个C++代码写在代码块中,但是我不知道如何链接它。我想让人们能够在不安装任何库或包的情况下编译我的项目。所以我把从他们的网页下载的allegro目录放入项目文件夹。接下来我包括了图书馆 #include "allegro/include/allegro5/allegro5.h"_C++_C++11_Allegro_Allegro5 - Fatal编程技术网

如何将allegro5库链接到C++;项目 我有一个C++代码写在代码块中,但是我不知道如何链接它。我想让人们能够在不安装任何库或包的情况下编译我的项目。所以我把从他们的网页下载的allegro目录放入项目文件夹。接下来我包括了图书馆 #include "allegro/include/allegro5/allegro5.h"

如何将allegro5库链接到C++;项目 我有一个C++代码写在代码块中,但是我不知道如何链接它。我想让人们能够在不安装任何库或包的情况下编译我的项目。所以我把从他们的网页下载的allegro目录放入项目文件夹。接下来我包括了图书馆 #include "allegro/include/allegro5/allegro5.h",c++,c++11,allegro,allegro5,C++,C++11,Allegro,Allegro5,但是当我试图编译时,我遇到了一个错误 /home/stanek/ClionProjects/proj/guiMain.cpp:17: undefined reference to `al_install_system' /home/stanek/ClionProjects/proj/guiMain.cpp:22: undefined reference to `al_create_display' /home/stanek/ClionProjects/proj/guiMain.cpp:28: u

但是当我试图编译时,我遇到了一个错误

/home/stanek/ClionProjects/proj/guiMain.cpp:17: undefined reference to `al_install_system'
/home/stanek/ClionProjects/proj/guiMain.cpp:22: undefined reference to `al_create_display'
/home/stanek/ClionProjects/proj/guiMain.cpp:28: undefined reference to `al_map_rgb'
/home/stanek/ClionProjects/proj/guiMain.cpp:28: undefined reference to `al_clear_to_color'
/home/stanek/ClionProjects/proj/guiMain.cpp:30: undefined reference to `al_flip_display'
/home/stanek/ClionProjects/proj/guiMain.cpp:32: undefined reference to `al_rest'
/home/stanek/ClionProjects/proj/guiMain.cpp:34: undefined reference to `al_destroy_display'
这是我的guiMain.cpp:

#include <iostream>
#include "allegro/include/allegro5/allegro5.h"


using namespace std;

int main(int argc, char **argv){

    ALLEGRO_DISPLAY *display = NULL;

    if(!al_init()) {
        fprintf(stderr, "failed to initialize allegro!\n");
        return -1;
    }

    display = al_create_display(640, 480);
    if(!display) {
        fprintf(stderr, "failed to create display!\n");
        return -1;
    }

    al_clear_to_color(al_map_rgb(0,0,0));

    al_flip_display();

    al_rest(10.0);

    al_destroy_display(display);

    return 0;
}
更新: 我已更改了CMAKEL列表中的设置

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -std=c++11 'pkg-config --cflags --libs allegro-5.0 '")
但我有一个错误:

    Error:Configuration proj [Debug]
Compiler exited with error code 1: /usr/bin/c++ -xc++ -g -Wall -std=c++11 'pkg-config --cflags --libs allegro-5.0 ' -g -v -dD -E
c++: error: pkg-config --cflags --libs allegro-5.0 : No such file or directory
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-5-20160209/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 5.3.0 (GCC) 

实际上,允许其他人玩你的游戏而不在他们的系统上安装allegro库是可能的

一种方法是将可执行文件静态链接到 快板图书馆。allegro维基实际上有一个 关于如何使用代码::块执行此操作

简言之,静态链接直接包含Allegro的必要部分 您的可执行文件,以便用户在运行时不必担心链接问题 它

另一种选择是使用动态链接,但打包所需的动态链接 图书馆随着你的游戏。例如 您的游戏文件夹可能如下所示:

bin/
    my_game.exe
    liballegro.dll
    liballegro_color.dll
    ...
然后,用户可以链接到您提供的库,而不必担心系统上安装了什么

请注意,动态库通常以
.so
(Linux)或
.dll
(Windows)结尾,而静态库以
.a
结尾

编辑:


你刚才说编译而不是运行。如果您想让他们自己编译,您需要包括库或指导他们如何自己获取库。

“我想让人们能够在不安装任何库或包的情况下编译我的项目。”这是不可能的。哦,对了,所以我必须在我的计算机上安装allegro,我想将我的项目发送给我的讲师,然后他也必须安装allegro?是的,您还必须链接库以消除链接器错误。那么我是否应该更改我的cmakelist?是的,您需要添加适当的链接器标志。好的,谢谢。但即使我安装了allegro并包含“#include”,我仍然会遇到相同的错误。包含标题是不够的,您需要链接到库。请参阅上面的链接或
Error:Configuration proj [Release]
Compiler exited with error code 1: /usr/bin/c++ -xc++ -g -Wall -std=c++11 'pkg-config --cflags --libs allegro-5.0 ' -O3 -DNDEBUG -v -dD -E
c++: error: pkg-config --cflags --libs allegro-5.0 : No such file or directory
Using built-in specs.
COLLECT_GCC=/usr/bin/c++
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-5-20160209/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 5.3.0 (GCC)
bin/
    my_game.exe
    liballegro.dll
    liballegro_color.dll
    ...