Search code examples
g++mingwdynamic-linkingportaudio

How to link an .la file using Mingw


I'm building portaudio under Windows 10, and I don't know how to link the libportaudio.la file under my portaudio build directory.

I used MSYS with MinGW to build portaudio, following this: http://portaudio.com/docs/v19-doxydocs/compile_windows_mingw.html

(But I didn't make install)

My build command in cmd is:

g++ test.cpp -I"portaudio_dir/include" -L"portaudio_dir/lib" -lportaudio

and it fails with cannot find lportaudio


Solution

  • The file libportaudio.la that you assume to be the PortAudio library you have just built is not a library.

    $ file libportaudio.la 
    libportaudio.la: libtool library file, ASCII text
    

    It is a text file of key-value pairs that that libtool generates to facilitate platform-independent linkage of the actual library in GNU autotools projects, such PortAudio itself. You can open it in your text editor and read it.

    The real (static and dynamic) PortAudio libraries that you built with:

    ./configure
    make
    

    are located in a hidden subdirectory:

    portaudio/lib/.libs
    

    which is usual for libraries built with autotools. It is expected that after make you will run make install (as root), which will copy the libraries and their associated header files to the default installation directories, or the alternative ones that you specified with:

    ./configure PREFIX=<prefix_dir>
    

    As you say, you didn't run make install. If you want to link a program against libportaudio while the static and dynamic libraries remain only in the build directory, you need:

    $ g++ test.cpp -I"portaudio_dir/include" -L"portaudio_dir/lib/.libs" -lportaudio
    

    But remember that even if you successfully link a program like this against the dynamic library portaudio_?.dll, that program will fail to load the DLL at runtime unless the OS loader can find the DLL by its standard DLL search algorithm

    The easiest - but not necessarily best - way to ensure the DLL is found at runtime is to copy it into the same directory as your program.