Compiling parts of Festival code written in C++ in a stand-alone C++ program

722 views Asked by At

I am trying to use selective parts of the Festival code (written in C++) and trying to use them in my own C++ programs. Note that this question is not about using the Festival API but about functions within Festival that can be used directly.

The program I wrote takes in a C++ style string and tries to initialize an object of type EST_String (an internal implementation of the String class in Festival). I then try to print the object.

The code I have:

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

I am trying to compile it (from the command line directly (no makefile at present)) like so:

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

The error I get is:

/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  

How can I get the code to compile properly? Where am I going wrong?

3

There are 3 answers

0
Some programmer dude On BEST ANSWER

Try putting the libraries you link with last on the line.

The linker often resolves references kind of "backwards", meaning that the order of files presented on the command line is important: It wants files containing references first, then the libraries containing those references.

0
c4pt On

Try adding this to end of your g++ link command: -I/usr/include/festival -I/usr/include/speech_tools -I/usr/include/boost -lFestival -lestools -lestbase -leststring

Making sure that the festival and speech_tools headers directory lives at: /usr/include

cd /usr/include
ls festival
ls speech_tools

I am trying to rebuild cogita with festival support, and my program linked successfully after compiling the object files using this line

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
sanjoyd On

I've been trying to link to festival's API too, and the Makefile I wrote executes the following link command

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

and I get a huge (25k lines) linker error full of undefined references (a part of which is here: http://pastebin.com/PCyV8xAH). I can assert that the *.a files exist (though I'm not sure if they've been built correctly or not). I compile speech_tools with make -j7 and festival with make.

Any suggestions?

I'm running Debian wheezy.