How do I install a c++ library so I can use it?

C++WindowsInstallationMingw

C++ Problem Overview


I have this library called BASS which is an audio library which I'm going to use to record with the microphone. I have all the files needed to use it, but I don't know how to install the library. I tried taking the example files and putting them in the same directory as the bass.h file. But I got a bunch of errors saying there are function calls that doesn't exist.

So my question is, how do I install it to be able to use it?

C++ Solutions


Solution 1 - C++

Installing a C++ library means specifying to interested software (eg. a compiler) the location of two kinds of files: headers (typical extensions *.h or .hpp) and compiled objects (.dll or *.lib for instance).

The headers will contain the declarations exposed to the developer by the library authors, and your program will #include them in its source code, the dll will contain the compiled code which will be or linked together and used by your program, and they will be found by the linker (or loaded dynamically, but this is another step).

So you need to

  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>

Last but not least, since I see that BASS library is a commercial product, probably they will have made available some installation instructions?

Solution 2 - C++

Run this command in a terminal or console.

cpp -v

Notice at the end of the output, you'll see a line like this:

#include<...> search starts here:

There will be a list of directories below that line. Move the package folder to one of those directories. Then try importing the module with <>.

Solution 3 - C++

See the code below code and don not forget to put bass.dll in the directory of your exe file and include the file bass.lib with your project and don not forget also to include the path to bass.h and bass.lib in the default include and lib path of your project.

#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;
}

Solution 4 - C++

If there are files named configure, Makefile or install you can try running them in that order. After that, any program that wants to link with this library must use a command like this:

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

The library path is usually the original library folder itself, unless you explicitly change it or the library itself puts its files in global locations like /usr/local or something like that.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrzetterbergView Question on Stackoverflow
Solution 1 - C++FrancescoView Answer on Stackoverflow
Solution 2 - C++Alex PayneView Answer on Stackoverflow
Solution 3 - C++NasserView Answer on Stackoverflow
Solution 4 - C++Arjun SingriView Answer on Stackoverflow