如何安装c ++库以便我可以使用它?

时间:2009-07-01 14:55:42

标签: c++ windows installation mingw

我有一个名为BASS的库,这是一个音频库,我将用它来录制麦克风。我有使用它所需的所有文件,但我不知道如何安装库。我尝试将示例文件放在与bass.h文件相同的目录中。但我得到了一堆错误,说有不存在的函数调用。

所以我的问题是,如何安装它才能使用它?

4 个答案:

答案 0 :(得分:15)

安装C ++库意味着向感兴趣的软件(例如编译器)指定两种文件的位置:标头(典型扩展名* .h或 .hpp)和编译对象( .dll或者* .lib例如)。

标题将包含库作者向开发人员公开的声明,并且您的程序将在其源代码中包含它们,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库是商业产品,他们可能会提供一些安装说明吗?

答案 1 :(得分:4)

请参阅下面的代码代码,不要忘记将bass.dll放在exe文件的目录中,并将文件bass.lib包含在您的项目中,不要忘记包括bass.h和bass的路径。 lib是项目的默认include和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;
}

答案 2 :(得分:1)

如果有名为configureMakefileinstall的文件,您可以尝试按此顺序运行它们。之后,任何想要与此库链接的程序都必须使用如下命令:

c++ <your_program.cpp> -l<library_name> -L<path_where_library_is_installed>

库路径通常是原始库文件夹本身,除非您明确更改它或库本身将其文件放在全局位置,如/usr/local或类似的东西。

答案 3 :(得分:0)

在终端或控制台中运行此命令。

cpp -v

请注意,在输出结尾处,您会看到如下所示的行:

#include<...> search starts here:

该行下面会有一个目录列表。 将包文件夹移动到其中一个目录。 然后尝试使用&lt;&gt;。

导入模块