在ubuntu中对espeak-ng标头的未定义引用 [英] Undifined reference to espeak-ng headers in ubuntu

查看:83
本文介绍了在ubuntu中对espeak-ng标头的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



I have downloaded `espeak-ng 1.1.49` and `./configure make make install` it, and tested it by `espeak --stdout "this is a test" | paplay` successfully and it worked. Then I tried to use it inside my C++ code(testSpeak.cpp) that I found on the internet as you can see below:

#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 -o speaks`我收到以下错误消息:


But after trying to make executable by this command: `g++ testSpeak.cpp -o speaks` I got these error messages:

/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新手,不知道如何解决它!我也搜索了很多,但无法理解解决方案:(



What I have tried:

I know the problem is about linking but as I am new to Linux, don't know how can I fix it! Also I searched a lot but couldn't understand the solutions :(

推荐答案

假设安装没问题,你可以解决问题

Assuming the installation is fine, you shuold issue
g++ testSpeak.cpp -o speaks -l espeak-ng


这篇关于在ubuntu中对espeak-ng标头的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆