This was solved by HolyBlackCat below, my issue was with linking. I think it is important that this question is not simply marked as a duplicate. The solution was not the same as other questions I viewed here, and turned out to be far simpler. My problem was not realizing the library required multiple links to function. All resources I checked online told me my PATH was wrong, or to add -I or -L options, none of which helped. I was only using pkg-config --libs --cflags libpulse
to find my necessary links and not pkg-config --libs --cflags libpulse-simple
as needed.
I am trying to create a simple program written in C that makes use of the pulseaudio
library. This is my file test.c
.
#include <stdio.h>
#include <pulse/simple.h>
#define SAMPLE_RATE 44100
#define BUFFER_SIZE 1024
int main(int argc, char *argv[]) {
pa_sample_spec sample_spec = {
.format = PA_SAMPLE_S16LE,
.rate = SAMPLE_RATE,
.channels = 1
};
pa_simple *pulse_input = pa_simple_new(
NULL, // Use the default server.
"My App", // Name of the application.
PA_STREAM_RECORD, // We want to record audio.
NULL, // Use the default device.
"Audio Input", // Description of the stream.
&sample_spec, // Sample format and rate.
NULL, // Use default channel map.
NULL, // Use default buffering attributes.
NULL // Ignore error code.
);
}
I performed all the necessary set up, but whenever I try to compile the program I get this error:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\msys64\tmp\ccyzDfRA.o:test.c:(.text+0x72): undefined reference to `pa_simple_new'
collect2.exe: error: ld returned 1 exit status
This doesn't make sense to me as intellisense is finding the header files fine, so I know they exist and when I run gcc -H test.c
I can see that C:/msys64/mingw64/include/pulse/simple.h
is being found.
I am at a bit of a loss as to why GCC is seemingly unable to read the header files.
To use GCC and compile my code I followed Microsoft's guide to setting up MSYS2
. I am using Mingw-w64
rather than UCRT
.
I added C:\msys64\mingw64\bin
to my PATH
.
I used pacman to install pulseaudio, specifically this version: https://packages.msys2.org/package/mingw-w64-x86_64-pulseaudio?repo=mingw64
This version matches the implementation of GCC I am using.
I try to compile test.c
using gcc -o test.exe test.c -lpulse
but it always seems to fail. I have confirmed that the header files are located in C:\msys64\mingw64\include\pulse
If you have any clue why this is not working, please let me know.