General question about c++ libraries

Discussion in 'Programmer's Corner' started by myamzen, May 9, 2009.

  1. myamzen

    Thread Starter New Member

    Apr 26, 2009
    Hello everyone,

    I am new to programming and I have started learning c++ recently.
    We designed a cd player for our final project in the cs class.

    and I was looking for a way to play mp3 files as well as cd files.
    I found many libraries on line (libWMP3, and STD) the problem is that they
    wouldn't compile (I'm using emacs) so do i have to download the library to
    my computer or is it built in in c++ ?

    Thanks 4 helping me

  2. Mark44

    Well-Known Member

    Nov 26, 2007
    A library is a binary file that contains compiled code for the functions and other things that the library exports. These libraries are not built into C++.

    When you create an application there are two main tools that are used: the compiler and the linker. The compiler translates the C++ code you wrote into machine code that is specific to the architecture your code will run on. This machine code is not complete, though. Any calls you made to standard library functions (such as printf and malloc if you used the older C functions) will fail until the linker brings in the code from the libraries that contain that code.

    You can't compile a library; it has already been compiled. What you need to do is download whatever library you end up using, and then link the library code to your code as part of the link step.

    You said you are using emacs. This is an editor that is part of the GNU open source collection. You are probably using the gcc compiler to do the actual code compilation. Look at the documentation for gcc, if that's what you're using, particularly "Options for Linking".
  3. mauro.laurenti

    Active Member

    May 8, 2009

    when you call g++ and in your program you have external library you downloaded,

    make sure to set properly the options

    -I : (i upper case) for the include path

    -L : for the library path

    -l : (low case L) with the library you use.


  4. myamzen

    Thread Starter New Member

    Apr 26, 2009
    Thanks guys that helped a lot :)