我有一个名为BASS的库,这是一个audio库,我将用它来logging麦克风。 我有所有需要使用它的文件,但我不知道如何安装库。 我试着把示例文件放在与bass.h文件相同的目录中。 但是我得到了一堆错误,说有不存在的函数调用。
所以我的问题是,如何安装它才能使用它?
安装C ++库意味着向感兴趣的软件(例如编译器)指定两种文件的位置:头文件(典型的扩展名* .h或.hpp)和编译的对象(例如 .dll或* .lib)。
这些头文件将包含库作者向开发者公开的声明,并且你的程序将#include它们的源代码,dll将包含编译后的代码,这些代码将会被连接在一起或者被你的程序使用,发现由链接器(或动态加载,但这是另一个步骤)。
所以你需要
1) put the header files in a location which your compiler is aware of (typically IDE allows to set so-called include directories, otherwise you specify a flag like "-I<path-to-headers>" when invoking the compiler) 2) put the dll files in a location which your linker is aware of (surely your IDE will allow that, otherwise you speficy a flag like "-L<path-to-libraries> -l<name-of-libraries>"
最后但并非最不重要,因为我看到BASS库是一个商业产品,可能他们会提供一些安装说明?
看到下面的代码的代码,不要忘记把bass.dll放在你的exe文件的目录中,并包括文件bass.lib与你的项目,不要忘了也包括在bass.h和bass.lib的路径默认包含和lib路径的项目。
#include <iostream> #include "bass.h" using namespace std; int main(int argc, const char **argv) { if (!BASS_Init(-1, 44100, 0, NULL ,NULL)) { cout<<"Can't initialize device"; return -1; } int stream = BASS_StreamCreateFile(false, "D:\\mypro\\Trans_Langs\\germ\\quran_amma\\Translations\\Sound_aya\\Sora1\\Hafs\\basfar\\a7.mp3", 0L, 0L, 0); if (stream != 0) { // play the stream channel BASS_ChannelPlay(stream, false); } else { // error creating the stream cout<<"Stream error: {0}", BASS_ErrorGetCode(); } getchar(); BASS_StreamFree(stream); // free BASS BASS_Free(); return 0; }
如果有文件命名为configure
, Makefile
或install
您可以尝试按顺序运行它们。 之后,任何想要链接到这个库的程序都必须使用这样的命令:
c++ <your_program.cpp> -l<library_name> -L<path_where_library_is_installed>
库路径通常是原始的库文件夹本身,除非你明确地改变它,或者库本身把它的文件放在像/usr/local
这样的全局位置上。
在终端或控制台中运行此命令。
cpp -v
注意在输出结尾,你会看到这样的一行:
#include<...> search starts here:
该行下面会有一个目录列表。 将包文件夹移动到这些目录之一。 然后尝试用<>导入模块。