使用cmake对espeak的未定义引用

时间:2016-07-02 22:51:16

标签: cmake espeak

我正在处理这个project,这是一个相关的issue 我用Espeak TTs引擎取代了TTS flite引擎,所以我不得不修改CmakeLists.txt

find_package(Espeak REQUIRED)
include_directories(${Espeak_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Espeak_LIBRARIES})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR} /cmake/Modules/")
if (NOT Espeak_Found)
    message(FATAL_ERROR "Package Espeak required, but not found!")
endif(NOT Espeak_Found)

因为默认情况下不支持FindEspeak.cmake所以我将文件添加到cmake默认模块路径,编译项目并获得以下错误

Linking CXX executable TextReading
CMakeFiles/TextReading.dir/EspeakBridge.cpp.o:(.bss+0x0): multiple definition of `samplerate'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x0): first defined here
CMakeFiles/TextReading.dir/EspeakBridge.cpp.o:(.bss+0x10): multiple definition of `sounddata'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x10): first defined here
CMakeFiles/TextReading.dir/EspeakBridge.cpp.o:(.bss+0x28): multiple definition of `counter'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x28): first defined here
CMakeFiles/TextReading.dir/EspeakBridge.cpp.o:(.bss+0x30): multiple definition of `waves'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x30): first defined here
CMakeFiles/TextReading.dir/EspeakBridge.cpp.o: In function `SynthCallback(short*, int, espeak_EVENT*)':
EspeakBridge.cpp:(.text+0x0): multiple definition of `SynthCallback(short*, int, espeak_EVENT*)'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:EspeakTTSWorker.cpp: (.text+0x0): first defined here
CMakeFiles/TextReading.dir/moc_EspeakTTSWorker.cxx.o:(.bss+0x0): multiple definition of `samplerate'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x0): first defined here
CMakeFiles/TextReading.dir/moc_EspeakTTSWorker.cxx.o:(.bss+0x10): multiple definition of `sounddata'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x10): first defined here
CMakeFiles/TextReading.dir/moc_EspeakTTSWorker.cxx.o:(.bss+0x28): multiple definition of `counter'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x28): first defined here
CMakeFiles/TextReading.dir/moc_EspeakTTSWorker.cxx.o:(.bss+0x30): multiple definition of `waves'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:(.bss+0x30): first defined here
 CMakeFiles/TextReading.dir/moc_EspeakTTSWorker.cxx.o: In function `SynthCallback(short*, int, espeak_EVENT*)':
 moc_EspeakTTSWorker.cxx:(.text+0x0): multiple definition of `SynthCallback(short*, int, espeak_EVENT*)'
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o:EspeakTTSWorker.cpp:(.text+0x0): first defined here
CMakeFiles/TextReading.dir/EspeakTTSWorker.cpp.o: In function `EspeakTTSWorker::run()':
 EspeakTTSWorker.cpp:(.text+0x118): undefined reference to `espeak_Initialize'
 CMakeFiles/TextReading.dir/EspeakBridge.cpp.o: In function `EspeakBridge::init()':
 EspeakBridge.cpp:(.text+0x93): undefined reference to `espeak_Initialize'
  EspeakBridge.cpp:(.text+0x9d): undefined reference to `espeak_SetVoiceByName'
  EspeakBridge.cpp:(.text+0xa7): undefined reference to `espeak_SetSynthCallback'
  CMakeFiles/TextReading.dir/EspeakBridge.cpp.o: In function  `EspeakBridge::close()':
  EspeakBridge.cpp:(.text+0x173): undefined reference to `espeak_Terminate'
  CMakeFiles/TextReading.dir/EspeakBridge.cpp.o: In function `EspeakTTSWorker::setText(std::string const&)':
   EspeakBridge.cpp:(.text._ZN15EspeakTTSWorker7setTextERKSs[_ZN15EspeakTTSWorker7setTextERKSs]+0x121): undefined reference to `espeak_Synth'
   EspeakBridge.cpp:(.text._ZN15EspeakTTSWorker7setTextERKSs[_ZN15EspeakTTSWorker7setTextERKSs]+0x126): undefined reference to `espeak_Synchronize'
  collect2: error: ld returned 1 exit status
  make[2]: *** [TextReading] Error 1
  make[1]: *** [CMakeFiles/TextReading.dir/all] Error 2
  make: *** [all] Error 2`

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我刚编辑了Espeak参数

 ############ Find ESPEAK TTS ############ 

find_path(LIBESPEAK_INCLUDE_DIRS 
          NAMES speak_lib.h
          HINTS /usr/include/espeak)
find_library(LIBESPEAK_LIBRARIES
             NAMES espeak
             HINTS /usr/lib/ /usr/x86_64-linux-gnu/
             PATH_SUFFIXES lib)

######################################## 


add_executable(TextReading 
        ${DAD_SOURCES} 
        ${DAD_HEADERS} 
        ${MY_UI_HDRS} 
        ${MY_MOC_SRCS} 
    ${MY_CUDA_COMPILED_FILES} 
    ${QEXTSERIALPORT_SOURCES} ${QEXTSERIALPORT_HEADERS} 
    )