[英]Compiling parts of Festival code written in C++ in a stand-alone C++ program
我試圖使用Festival
代碼的選擇部分(用C ++編寫)並嘗試在我自己的C++
程序中使用它們。 請注意,這個問題是不是使用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
如何才能正確編譯代碼? 我哪里錯了?
嘗試將此添加到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
嘗試將最后鏈接的庫放在最后一行。
鏈接器通常會解析引用類型的“向后”,這意味着命令行上顯示的文件順序很重要:它首先需要包含引用的文件,然后是包含這些引用的庫。
我一直在嘗試鏈接到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文件存在(雖然我不確定它們是否已經正確構建)。 我編譯speech_tools make -j7
和節日用make
。
有什么建議么?
我正在運行Debian wheezy。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.