Compile Programs and Link portaudio_x86.lib

  1. The "portaudio_x86.lib" which you obtained in the previous stage is a library, so you can develop applications invoking functions defined in that library.

  2. Let's write a simple program which invokes Pa_GetVersion() and Pa_GetVersionText():

    #include <stdio.h>
    #include "portaudio.h"
    
    int main() {
        printf("%x\n%s\n", Pa_GetVersion(), Pa_GetVersionText());
        return 0;
    }
    
  3. In Visual Studio, press Ctrl-Shift-N to create a new project "PA01" (which stands for "PortAudio 01") as an "Empty Project". Because this solution only consists of a project, you don't need to check "Create directory for solution".

  4. Press Ctrl-Shift-A to add a new item in "Source Files". You may choose an arbitrary filename, or choose a filename which is the same as the project name ("pa01.cpp").

  5. Copy and paste the above code into the editor. Now it still cannot be compiled sucessfully, because Visual C++ doesn't know where to include "portaudio.h".

  6. Project - Properties - C/C++ - General - Additional Include Directories

    • Choose "include" under your "portaudio" directory.
  7. Click the "pa01.cpp" file and press Ctrl-F7 to compile. This time it is compiled successfully. A file "PA01.OBJ" is generated under "source/repos/PA01/Debug".

  8. Try to "build" the project by clicking Ctrl-Shift-B. This will try to link "PA01.OBJ" with the PortAudio library. However, it complains "unresolved external symbol" because Visual C++ has no idea about which library to link. You must specify "portaudio.lib" as the external library to link.

  9. In "Solution Explorer", click the project "PA01" (not the solution, not the pa01.cpp file).

    • Linker - Input - Addition Dependencies.
    • Fill in the full path of the library. In my case, it is "M:/PortAudio/portaudio/build/msvc/Win32/Debug/portaudio_x86.lib".
  10. Now Ctrl-Shift-B should build the project successfully and generate an executable file "PA01.EXE" under "source/repos/PA01/Debug", too.

  11. Running the "PA01.EXE" program will cause an error, because it fails to find "portaudio.dll".

  12. The simplest solution is to copy your "portaudio_x86.dll" to the same directory as PA01.EXE. Now you can run "PA01.EXE" successfully.

  • If you prefer to run the program by Ctrl-F5 directly in Visual Studio, put "portaudio_x86.dll" in the "PA01" directory instead of "PA01/Debug".

Compile a Program with "Release" Model

  1. Create an empty project "PA02".
  2. In "Source Files", add an "Existing Item"
  3. Configure the project properties to specify the INCLUDE directory and linking library "portaudio_x86.lib".
  4. Build and generate "PA02.EXE". This program will list all audio devices and their capacities.
  5. If you copy "PA02.EXE" (including portaudio.dll, certainly) to another PC which does not install Visual Studio, the program fails to execute because it lacks several DLL files.
  6. You need to build it in "Release" mode. Now you see another "PA02.EXE" under "source/repo/PA02/Release".
  7. Copy this file to the PC where Visual Studio is not installed, the program can run successfully. (You still need "portaudio_x86.dll", certainly.)