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; 
} 

내가 컴파일과 같이 (직접 명령 줄 현재 (NO 메이크)에서) 노력하고 있어요 : 내가 오류가

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에 링크하려고했는데

, 내가 쓴 메이크는 다음 링크 명령

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 파일이 있다고 주장 할 수 있습니다 (올바르게 작성되었는지 확실하지는 않지만). speech_tools를 make -j7, 축제를 make으로 컴파일합니다.

제안 사항?

나는 데비안 wheezy를 실행 중입니다. 축제와 speech_tools 헤더 디렉토리에서 살고 있는지 만들기 -I/usr/include/festival -I/usr/include/speech_tools -I/usr/include/boost -lFestival -lestools -lestbase -leststring

: /usr/include

cd /usr/include 
ls festival 
ls speech_tools 

나는 축제 지원 cogita을 다시 시도하고,이 추가

1

시도는 g의 ++ 링크 명령을 종료합니다 및이 줄을 사용하여 개체 파일을 컴파일 한 후 내 프로그램이 성공적으로 연결되었습니다.

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