c++ - Ubuntu 中对 espeak-ng header 的 undefined reference

标签 c++ ubuntu error-handling undefined-reference espeak

我已经下载了espeak-ng 1.1.49./configure make make install它,并通过espeak --stdout“这是一个测试” | papplay 成功并且有效。然后我尝试在我在互联网上找到的 C++ 代码(testSpeak.cpp)中使用它,如下所示:

#include <string.h>
#include <vector> 
#include </usr/local/include/espeak-ng/speak_lib.h> 

int samplerate; // determined by espeak, will be in Hertz (Hz)
const int buflength = 200; // passed to espeak, in milliseconds (ms)

std::vector<short> sounddata;

int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
    if (wav == NULL)
        return 1; // NULL means done.

    /* process your samples here, let's just gather them */
    sounddata.insert(sounddata.end(), wav, wav + numsamples);
    return 0; // 0 continues synthesis, 1 aborts 
}

int main(int argc, char* argv[] ) {
    char text[] = {"my name is espeak"};
    samplerate = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, buflength, NULL, 0);
    espeak_SetSynthCallback(&SynthCallback);
    espeak_SetVoiceByName("en"); 
    unsigned int flags=espeakCHARS_AUTO | espeakENDPAUSE;
    size_t size = strlen(text); 
    espeak_Synth(text, size + 1, 0, POS_CHARACTER, 0, flags, NULL, NULL); 
    espeak_Synchronize();

    /* in theory sounddata holds your samples now... */

    return 0; 
}

但是在尝试通过此命令使其可执行后:g++ testSpeak.cpp -ospokes我收到了这些错误消息:

/tmp/ccR9O0vw.o: In function `main':
testSpeak.cpp:(.text+0x78): undefined reference to `espeak_Initialize'
testSpeak.cpp:(.text+0x90): undefined reference to `espeak_SetSynthCallback'
testSpeak.cpp:(.text+0x9c): undefined reference to `espeak_SetVoiceByName'
testSpeak.cpp:(.text+0xce): undefined reference to `espeak_Synth'
testSpeak.cpp:(.text+0xd2): undefined reference to `espeak_Synchronize'
collect2: error: ld returned 1 exit status

我知道问题出在链接上,但由于我是 Linux 新手,不知道如何解决它!我也搜索了很多但无法理解解决方案:(

最佳答案

我可以正确编译并尝试安装

sudo apt-get install espeak-data libespeak-dev espeak-ng

您的包含内容是

   #include </usr/local/include/espeak-ng/speak_lib.h> 

成功

   #include <espeak-ng/speak_lib.h>

你的编译命令是

g++ testSpeak.cpp -o speaks

试试这个吧

g++ -W -o speaks myEspeak.cpp -lespeak

引用我不会编译它艰难的尝试,它可能无法工作旧版本,但使用您提供的代码并安装这些程序并更改您的包含,您的代码将编译。我没有做太多事情,我会找到一种方法将其存储到 .wav 文件中。

http://apexlogic.net/code-bank/c-2/espeak-basic-usage-example/

当你从共享库编译时,你需要将它链接到类似的东西

 -lespeak 

关于c++ - Ubuntu 中对 espeak-ng header 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47027953/

相关文章:

c++ - C++中如何剪切和粘贴文件

c++ - 为什么我必须在抽象类上实现具体的析构函数?

ubuntu - 找不到包含 'GObject-2.0.gir'

Linux LS 命令无法与 * 正则表达式量词一起正常工作

ubuntu - 如何将ssh指向配置文件

c++ - Boost::Spirit - on_error 不打印

c++ - CMake 找不到 OpenCV 库

c++ - 我应该按什么顺序构建我的 C++ 静态库

node.js - <!Doctype上 Uncaught SyntaxError

php - PHP : What's the best practice for catching PHP errors? [closed]