[Portaudio] Undefined reference errors to compile a sample portaudio program!

Richard Ash richard at audacityteam.org
Sat Oct 16 12:17:46 EDT 2010


On Fri, 2010-10-15 at 11:52 -0400, Abhishek Bhattacharya wrote:
> I am trying to compile a sample portaudio program by linking with static
> library. I have not installed in my machine since I have don't have root
> permissions and so would like to use by linking with static library.
> My environment is Ubuntu 10.04.
> I think that I am making some mistake in linking since it is giving me
> many undefined reference errors as follows:
> 
> ****************************************************************************
> abhat002 at shetland:~/third_party 192% gcc -Wall -I/portaudio/include -o rec
> patest_record.c -L./lib -lportaudio-x86_64-unknown-linux-gnu -lpthread
> ./lib/libportaudio-x86_64-unknown-linux-gnu.a(pa_unix_util.o): In function
> `PaUnixThread_New':
> pa_unix_util.c:(.text+0x70e): undefined reference to `floor'
> ./lib/libportaudio-x86_64-unknown-linux-gnu.a(pa_linux_alsa.o): In
> function `PaAlsa_GetStreamOutputCard':
> ***************************************************************************

You are linking to the static library (which does not contain any
dependency information), but you aren't providing any of the necessary
dependent libraries to the linker. Of course this results in a link
problem, because the required libraries aren't present.

You have three possible options:
1. Figure out what libraries you need, and add them manually. That's
going to get tedious, the first two you need for the errors above are
-lm and -lasound
2. Use libtool to link your executable, in which case libtool reads
the .la file and does the above for you. On the other hand, it means
getting to grips with libtool.
3. Use pkg-config to obtain the list of libraries (LDFLAGS variable) and
add them to your compile command. This is easier to make work (because
it doesn't involve libtool), but you have to tell pkg-config where to
find the .pc file for your uninstalled copy of portaudio, then grab the
linker flags, then actually do the link yourself with those flags.

None of this is portaudio-specific, it's general *nix build system
(especially the first point that static libraries don't carry their
dependencies and so always have to have them explicitly provided (in the
right order) at link time).

Richard Ash



More information about the Portaudio mailing list