web-dev-qa-db-ja.com

gcc未定義の参照

私は走っています。

gcc -c -I/usr/vt/sample ttssample.c
gcc -L. -lttsapi ttssample.o -o ttsample

次のエラーが発生します...

ttssample.o: In function `_TTSFile':
ttssample.c:(.text+0x352): undefined reference to `TTSRequestFile'
ttssample.o: In function `_TTSFileEx':
ttssample.c:(.text+0x5e0): undefined reference to `TTSRequestFileEx'
ttssample.o: In function `_TTSBuffer':
ttssample.c:(.text+0x833): undefined reference to `_TTSRequestBuffer'
ttssample.o: In function `_TTSBufferEx':
ttssample.c:(.text+0xabd): undefined reference to `_TTSRequestBufferEx'
ttssample.o: In function `_TTSBuffering_cont':
ttssample.c:(.text+0xcbf): undefined reference to `_TTSRequestBuffer'
ttssample.o: In function `_TTSBuffering_stop':
ttssample.c:(.text+0xf2d): undefined reference to `_TTSRequestBuffer'
ttssample.o: In function `_TTSBuffering_SSML':
ttssample.c:(.text+0x122b): undefined reference to `_TTSRequestBufferSSMLEx'   
ttssample.o: In function `_TTSStatus':
ttssample.c:(.text+0x157b): undefined reference to `TTSRequestStatus'
collect2: ld returned 1 exit status

tTSRequestFileはlibヘッダーにありますが、その前にDllExportがありますが、これがエラーの原因であると思いますか?どんな助けでも大歓迎です。

DllExport int TTSRequestFile(char *szServer, int nPort, char *pText, int nTextLen, char *szSaveDir, char *szSaveFile, int nSpeakerID, int nVoiceFormat);
9
JLB

リンクコマンドが間違っています。コマンドの最後にライブラリを指定する必要があります。

gcc ttssample.o -o ttsample-L。 -lttsapi
22
Nikos C.

次のように、ifdefines呼び出しの周りにプリプロセッサDllExportを追加できます。

#ifdef _WIN32
// we are on windows

#Elif defined __linux__
//we are on linux

#Elif defined __Apple__&__MACH__
// we are on mac

#endif // os specific

クロスプラットフォームをコンパイルしている3つのプラットフォームに追加しました。プラットフォームを認識するために使用するキーワードは変更される可能性がありますが、_WIN321つはWindows7と8でテストされています。1年前にsourceforgeで見つけたと思います。現在、ページが見つかりませんでしたが、見つかった場合は折り返しご連絡いたします。

Nikos Cの回答についてはまだコメントできないので、ここでコメントします。 あなたのリンクコマンドは正しいです、もちろん私はあなたのファイルを見ることができないので、あなたのパスは正しいと思います。 重要なのは-lは依存関係に応じて正しい順序である必要がありますが、これは私が経験した限りでは通常問題ではありません。

0