To register and login, use your Google, Twitter, Facebook, LinkedIn, or OpenID credentials.

This is allowing us to stop most spam registrations. We've deleted most of the spam accounts that got through, and we're closely watching for more.

Can't compile a basic program with portsf on code::blocks

athosathos Posts: 2
hi all, i am studying the book, and i tried to build a small program using the psf_sndOpen function from portsf library. I'm using code::blocks on ubuntu, i grabbed the four library files (from the 2nd chapter folder), put them in a folder on my hd and indicated the path in code::blocks, going in Settings->Compiler and debugger->Search directories. I did this both for linker and compiler.

Then i included in my file, and i guess it could see it because the auto-complete feature shows names from the library while i'm writing, but when i try to compile i get these errors:

undefined reference to 'psf_init'
undefined reference to 'psf_sndOpen'
undefined reference to 'psf_finish'

I tried searching on the web and i read that i should indicate the libraries in Settings->Compiler and debugger->Linker settings as well, but it asks for .a, .so or .lib files, which i don't have.

I don't know what to do, is there anyone who uses codeblocks and can help me?


  • AmirAmir Posts: 1

    I am on Mac using Terminal for compilation and I also had trouble starting with portsf library.
    I figured that you cannot use the 4 files directly as you described. You will need to build a library from those 4 files which is (once you know how it's done) rather easy.

    1) Copy the complete folder
    "/Volumes/Audio_Programming_Book_V1/Code/BookCode/chapters/02dobsonBOOKexamples" to your desktop or any folder you like.

    2) open a Terminal/Console window and go to the just created folder on your HD

    3) Type "make" and hit enter. This will compile the 4 files into 1 library file (called "libportsf.a") which you can find now in the "lib" subfolder (which has been empty before).

    4) Now you can use the library and you only need to include "portsf.h" in your projects.

    5) Compiling a source *.c file which uses portsf works as follows for me:
    In Terminal go to the folder which contains the "portsf.h" & the "/lib/libportsf.a" files
    and type ("sine.c" stands for any file you want to compile ):
    gcc sine.c -o sine -I include -Llib -lportsf -lm

    gcc ... call the c compiler
    sine.c ... the source file
    -o sine ... specify the output file name
    -I include ... the include folder for header files containing the portsf.h file
    -Llib -lpostsf ... give the location of the library file
    -lm ... don't know (?)

    6) finally you can use the created executable in Terminal typing:

     ./sine arguments_list

    Just try to compile the *.c files that are already contained as *.c and executables in the mentioned folder.
    Hope I could help you in any way, since it also gave me some headache starting out! Kind regards.

  • JFC! That worked. Thanks.

Sign In or Register to comment.