0

I'm trying to write a simple program with PulseAudio lib. Everything is fine when it compiles under gcc (gcc -o name_one name_two.cpp -lpulse-simple -lpulse), but when I copy my program to cLion (under cmake) it throws up an error:

main.cpp:49: undefined reference to pa_simple_new
main.cpp:50: undefined reference to pa_strerror
main.cpp:78: undefined reference to pa_simple_drain
main.cpp:72: undefined reference to pa_simple_write
main.cpp:73: undefined reference to pa_strerror
main.cpp:79: undefined reference to pa_strerror
main.cpp:85: undefined reference to pa_simple_free

I've tried to add links (-lpulse-simple -lpulse) into my makeafile.txt like this:

add_compile_options(-lpulse-simple -lpulse)

but this is not working.

How to do it properly?

kefirek09
  • 31
  • 1
  • 5

1 Answers1

3

After adding

target_link_libraries("project name" pulse-simple pulse)

to my code, it was still occurating an error (library not found). I found on github this lines:

find_path(PULSEAUDIO_INCLUDE_DIR
        NAMES pulse/pulseaudio.h
        DOC "The PulseAudio include directory"
        )

find_library(PULSEAUDIO_LIBRARY
        NAMES pulse
        DOC "The PulseAudio library"
        )

and I added them to the file. Everything works fine, copy of my cmake file:

cmake_minimum_required(VERSION 3.8)
project(Audio)
set(CMAKE_CXX_STANDARD 11)
find_path(PULSEAUDIO_INCLUDE_DIR
        NAMES pulse/pulseaudio.h
        DOC "The PulseAudio include directory"
        )
find_library(PULSEAUDIO_LIBRARY
        NAMES pulse
        DOC "The PulseAudio library"
        )
include_directories(${PULSEAUDIO_INCLUDE_DIRS})
set(SOURCE_FILES main.cpp)
add_executable(Audio ${SOURCE_FILES})
target_link_libraries(Audio pulse-simple pulse)
kefirek09
  • 31
  • 1
  • 5