PulseAudio不会在cmake上编译

时间:2017-09-28 12:06:45

标签: c++11 gcc cmake pulseaudio

我试图用PulseAudio lib编写一个简单的程序。当它在gcc(gcc -o name_one name_two.cpp -lpulse-simple -lpulse)下编译时,一切都很好,但当我将我的程序复制到cLion(在cmake下)时,它会抛出一个错误:

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

我试图将链接(-lpulse-simple -lpulse)添加到我的makeafile.txt中,如下所示:

add_compile_options(-lpulse-simple -lpulse)

但这不起作用。

怎么做得好?

1 个答案:

答案 0 :(得分:0)

添加

target_link_libraries("project name" pulse-simple pulse)

到我的代码,它仍然出现错误(未找到库)。我在github上找到了这句话:

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

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

我将它们添加到文件中。一切正常,我的cmake文件的副本:

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)