在独立的C ++程序中编译用C ++编写的Festival代码部分

问题描述 投票:0回答:3

我试图使用Festival代码的选择部分(用C ++编写)并尝试在我自己的C++程序中使用它们。请注意,这个问题不是关于使用Festival API,而是关于Festival中可以直接使用的函数。

我编写的程序采用C++样式string并尝试初始化类型为EST_String的对象(Festival中String类的内部实现)。然后我尝试打印对象。

我的代码:

/*EST_String is a string implementation for the festival project.
 * This program simply takes in a C++-style string and returns an EST_String. 
 * This program is being used to test for makefiles etc.
 */

#include <iostream>
#include <EST_String.h>
#include <string>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[]) {

  if(argc != 2) {
    cout << "Correct usage: <binary> <string>" << endl;
    exit(5);
  }

  string word(argv[1]);
  EST_String e(word.c_str());  //init EST_String.

  cout << "C++ String = " << word << endl;
  cout << "EST_String = ";
  cout << e;

  return 0;
}  

我正在尝试编译它(从命令行直接编译(目前没有makefile)),如下所示:

g++ -I../../speech_tools/include -I../../speech_tools/base_class/string -L../../speech_tools/lib/ -lestbase -lncurses -lasound -leststring -lestools usingESTString.C -o usingESTString  

我得到的错误是:

/tmp/cczyGTfm.o: In function `main':
usingESTString.C:(.text+0x91): undefined reference to `EST_String::EST_String(char const*)'
/tmp/cczyGTfm.o: In function `EST_Chunk::operator--()':
usingESTString.C:(.text._ZN9EST_ChunkmmEv[EST_Chunk::operator--()]+0x3e): undefined reference to `EST_Chunk::~EST_Chunk()'
usingESTString.C:(.text._ZN9EST_ChunkmmEv[EST_Chunk::operator--()]+0x49): undefined reference to `EST_Chunk::operator delete(void*)'
collect2: ld returned 1 exit status  

如何才能正确编译代码?我哪里错了?

c++ compilation festival
3个回答
1
投票

尝试将最后链接的库放在最后一行。

链接器通常会解析引用类型的“向后”,这意味着命令行上显示的文件顺序很重要:它首先需要包含引用的文件,然后是包含这些引用的库。


1
投票

尝试将此添加到g ++链接命令的末尾:-I/usr/include/festival -I/usr/include/speech_tools -I/usr/include/boost -lFestival -lestools -lestbase -leststring

确保festival和speech_tools标题目录位于:/usr/include

cd /usr/include
ls festival
ls speech_tools

我正在尝试用节日支持重建cogita,并且在使用此行编译目标文件后我的程序成功链接

g++ -Wall -fPIC -Wno-variadic-macros -fopenmp -std=gnu++0x -O2 -g -fstack-protector cogitaconfig.o go-irc.o irc.o whirr-sockets.o -o cogIRCProgram -rdynamic /usr/local/lib/libcogutil.so -Wl,-rpath,/usr/local/lib -I/usr/include/festival -I/usr/include/speech_tools -I/usr/include/boost -lFestival -lestools -lestbase -leststring


0
投票

我一直在尝试链接到festival的API,我编写的Makefile执行以下链接命令

g++ -lpthread build/fetch/festival/src/lib/libFestival.a  build/fetch/speech_tools/lib/libestools.a  build/fetch/speech_tools/lib/libestbase.a build/fetch/speech_tools/lib/libeststring.a -lcurses -ldl -lm -lstdc++ build/test/speaker.o build/common/message-queue.o build/speaker/speaker-public.o build/fetch/festival/src/lib/libFestival.a -o build/bin/speaker-test

我得到一个巨大的(25k行)链接器错误,其中包含未定义的引用(其中一部分在这里:http://pastebin.com/PCyV8xAH)。我可以断言* .a文件存在(虽然我不确定它们是否已经正确构建)。我用make -j7make节日编译speech_tools。

有什么建议?

我正在运行Debian wheezy。

© www.soinside.com 2019 - 2024. All rights reserved.