2012-01-19 4 views
0

Festivalコードの選択部分(C++で書かれている)を使い、自分のC++プログラムで使用しようとしています。この質問は、Festival APIの使用についてではなく、直接使用できるFestivalの機能についてです。スタンドアロンC++プログラムでC++で書かれたフェスティバルコードの一部をコンパイル

私が書いたプログラムがC++スタイルstringに取り、タイプEST_String(祭で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; 
} 

に私はそうのように(直接コマンドライン現時点では(ノーメイクファイル)から)それをコンパイルしようとしています:

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 

コードを正しくコンパイルするにはどうすればよいですか?どこが間違っていますか?

+1

最後にリンクしたライブラリをコマンドラインで、特にソースファイルの後ろに置いてみてください。 –

+0

@ジョアヒム:そうです。それが問題でした。なぜあなたは答えにあなたのコメントをしていないと私はそれを正しいとして受け入れるだろう。小さな説明も素晴らしいでしょう。ありがとう! – Sriram

答えて

1

リンク先のライブラリを最後に置いてみてください。

リンカは、参照の種類を "後方"に解決することがあります。つまり、コマンドラインで表示されるファイルの順序が重要です。まず参照を含むファイル、次にそれらの参照を含むライブラリが必要です。

0
私もお祭りの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ライン)リンカエラーを取得する(Aその一部はここにあります:http://pastebin.com/PCyV8xAH)。 * .aファイルが存在すると主張することができます(ただし、正しく構築されているかどうかはわかりませんが)。私はmake -j7とspeech_toolsをコンパイルし、makeとフェスティバルをコンパイルします。

提案がありますか?

私はDebian wheezyを実行しています。あなたのG ++リンクコマンドの最後にこれを追加すること

1

試してみてください。-I/usr/include/festival -I/usr/include/speech_tools -I/usr/include/boost -lFestival -lestools -lestbase -leststring

祭りと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

関連する問題