How to link festival TTS libraries in a C++ programme using g++ - c++

i am using Festival c++ Api but in the manual provided at
http://www.cstr.ed.ac.uk/projects/festival/manual/festival_28.html#SEC132
saying to link festival/src/lib/libFestival.a etc.
so please tell me hw to link them with my c++ programme

The simplest way to link a static library from g++ is simply to name the library on the command line, using the complete path:
g++ mycode.cpp -o myprog /myinstall/festival/src/lib/libFestival.a
where /myinstall is wherever you installed the libraries. You can also specify the path and the library with the -L and -l flags:
g++ mycode.cpp -o myprog -L/myinstall/festival/src/lib -lFestival

I assume that you put your file.cpp in the directory containing festival and speech_tools which are extracted from packages.
compile:
g++ yourFile.cpp -o yourFile -I./festival/src/include -I./speech_tools/include -L./festival/src/lib -lFestival -L./speech_tools/lib/ -lestools -lestbase -leststring

Related

Cannot link the header file using gcc linker in windows

hello.c will use the header file plugin.h. If I want to use gcc to compile, can I know how should I write the -LXXX.
gcc -o hello hello.c -LXXX
Currently my project structure look like this
project directory is (C:\project)
project
examples/ hello.c
include / plugins/ plugin.h
You don't link the header file, you include it. You link object files and static/shared libraries, which are already compiled files.
But to answer your question, you include your plugin with the -I option.
g++ -O2 examples/hello.c -I include/plugins -o hello
Or if you have a library to link say in lib:
g++ -O2 examples/hello.c -I include/plugins -L lib/plugins -lplugin -o hello
Or if you want to do in two steps (notice the -c)
g++ -O2 -c examples/hello.c -I include/plugins -o hello.o
g++ hello.o -L lib/plugins -lplugin -o hello

linker delets library and does not recognize it

I am compiling a C program with g++ and linking it to a library mylib.lib which is located in the same folder as the sourcecode by:
user$ g++ myprog.c -o mylib.lib
and the compiler behaves in a strange way. first of all it gives the error 'undefined reference to fun1' . this should not happen because fun1 is in mylib.lib. secondly it deletes mylib.lib . I also tried a different way:
user$ g++ myprog.c mylib.lib
In this case I get the same error: 'undefined reference to fun1'
Finally I tried to add mylib by:
renamed mylib.lib to libmylib.lib
2.
user$ g++ myprog.c -L/Dima/Tests -l mylib
In this case the error is 'cannot find lmylib' although it is located in /Dima/Tests. how do I compile it correctly?
You're not building a library, you are trying to create an executable program named mylib.lib. That's why the linker is invoked.
If you want to create a library, it depends on the toolchain you target, but generally speaking you only create object files, and create an archive of those object files.
For the GNU toolchain (GCC and the GNU binutils linker) you use the ar program to create this archive.
$ g++ mylib.c -c # Create object file named `mylib.o`
$ ar crv libmylib.a mylib.o # Create the static library
Now you have a static library containing the object file myprog.o which is compiled from myprog.c. To use it do something like
$ g++ myprog.c -L. -lmylib -o myprog
The above command tells the linker to look in the current directory (-L.) and link with the library mylib (the linker automatically looks for libmylib.a).
Also, when using the GNU linker it's important that you put the libraries after any source or object files.

Executing a binary with a shared library in linux

I am making a simple hello world program to learn about linking shared libraries in linux. I have managed to compile the main program into an executable with the shared library using the following:
g++ -fPIC -c lab2_hello_main.cpp <--create position independent objects
g++ -fPIC -c lab2_hello_sub.cpp
g++ -fPIC -shared -Wl,-soname=libfuncs.so.1.0 *.o -o libfuncs.so.1.0 -lc <--make the shared library
ln -s libfuncs.so.1.0 libfuncs.so <-- soft links for compiling and running
ln -s libfuncs.so.1.0 libfuncs.so.1
g++ -o hello_dyn lab2_hello_main.cpp -L/mypath -lfuncs <-- Linking the library to main
When I do an ldd on hello_dyn I get an output stating that the library can't be found:
"libfuncs.so.1.0 => not found"
The other libraries it looks for automatically are fine.
Anyone know why this might be?
Your shared library's location is not in the linker's search path. You can confirm this by adding the directory in which your library is located to the LD_LIBRARY_PATH environment variable and then run ldd again. See the ld.so(8) man page for details.

Use Crypto++ in personal project on Windows

I have a small project to create in a course at my University that requires using the Crypto++ libraries. The requirement is that we don't include the whole source code/binary files of Crypto++ but link it from an outside directory. (E.g. C:\cryptopp). This is because the reviewer will link his/her own directory to asses my code.
Now, I am really bad at creating Makefiles and don't understand the content of them completely.
I am using MinGW on Windows 7.
So my main question would be, what do I need to write in the Makefile to use Crypto++ in my project from an outside folder?
Suppose you have the following makefile:
unit.exe: unit.o
g++ unit.o -o unit.exe
unit.o: unit.cc unit.h
g++ -c unit.cc -o unit.o
In order to modify it to use an external library you have to use the GCC -I and -L options:
unit.exe: unit.o
g++ unit.o -o unit.exe -L /c/cryptopp -l ws2_32 -l cryptopp
unit.o: unit.cc unit.h
g++ -I /c/cryptopp -c unit.cc -o unit.o
Often a makefile would contain a variable that is passed to the compiler and a variable that is passed to the linker, for example CFLAGS and LDFLAGS. If that is the case, then it might be easier to add the "-I" and "L" options to the compiler and linker variables.
See also here for a way to comiple CryptoPP.

compiling a c++ program including mysql

I'm new to gcc, and trying to compile a c++ program which includes mysql.h using the command:
g++ -o test test.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql
It works without issue, but I was wondering if someone could explain the arguments to me. I don't like using commands I don't understand.
Thanks
-o test means the output file is to be named "test".
test.cpp is your source file, of course.
-L/usr/include/mysql means to look for libraries in /usr/include/mysql, as well as in the usual link path. (It probably isn't finding any libraries here; my libmysqlclient.a is in the standard library directory /usr/lib. So I don't think you need this option.)
-lmysqlclient means to link with the mysqlclient library (actually named libmysqlclient.a)
-I/usr/include/mysql means to look for #include files in /usr/include/mysql, as well as in the usual include path.
try "man g++" for a full description of what the various options mean.
man gcc will give you the details of all these options.
g++ -o test test.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql
g++ : the compiler
-o test : name the resulting binary "test"
test.cpp : your source file
-L : the directory to look in for libraries (that are specified by -l)
-l : named library to link against (looks for it in -L)
-I : the directory to look in for #included header files