Cannot compile against gobject-2.0 - c

I am trying to learn the gobject system, so I read some of the documentation on the gnome site and made a simple gobject parented to GObject. I don't wan't to keep running the gcc job every time I want to compile, and I also wanted to learn a build system at the same time. I tried autotools, which I got working to the point where pkg-config searches for gobject-2.0.
To compile my project from the command line, I do: gcc *.c $(pkg-config --cflags --libs gobject-2.0) (I had to take out the extra ticks for formatting). Anyway <--- this command works.
However: gcc $(pkg-config --cflags --libs gobject-2.0) *.c, which SHOULD BE the SAME COMMAND, returns this:
main.c: In function 'main':
main.c:10:10: warning: initialization from incompatible pointer type [enabled by default]
/tmp/ccxO7wkX.o: In function `main':
main.c:(.text+0x1a): undefined reference to `g_type_init'
main.c:(.text+0x27): undefined reference to `g_type_create_instance'
/tmp/ccPu2beU.o: In function `a_get_type':
myobject.c:(.text+0x57): undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
Yes, it is the EXACT SAME COMMAND WITH ANOTHER ORDER. I have no clue what's going wrong. Here is how autotools/automake does the build:
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o
main.o: In function `main':
/home/aj/Desktop/GObjectTest/src/main.c:9: undefined reference to `g_type_init'
/home/aj/Desktop/GObjectTest/src/main.c:10: undefined reference to `g_type_create_instance'
myobject.o: In function `a_get_type':
/home/aj/Desktop/GObjectTest/src/myobject.c:19: undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
make: *** [GObjectTest] Error 1
Is this some quirky gcc compile thing? I tried with clang too no avail, which makes me think that this is a linker problem? I really have no idea, and was hoping that someone out there will. This is pretty frustrating.
Here is the "offending code":
GType a_get_type (void)
{
if (type == 0) {
GTypeInfo info = {
sizeof(AClass),
NULL,
NULL,
(GClassInitFunc) a_class_init,
NULL,
NULL,
sizeof(A),
0,
(GInstanceInitFunc) NULL
};
type = g_type_register_static (G_TYPE_OBJECT,
"AType",
&info, 0);
}
return type;
}
Edit: Here is the output of my autotools build, the make part anyway:
$ make
make all-recursive
make[1]: Entering directory `/home/aj/Desktop/GObjectTest'
Making all in src
make[2]: Entering directory `/home/aj/Desktop/GObjectTest/src'
gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.c
main.c: In function 'main':
main.c:10:10: warning: initialization from incompatible pointer type [enabled by default]
mv -f .deps/main.Tpo .deps/main.Po
gcc -DHAVE_CONFIG_H -I. -I.. -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -MT myobject.o -MD -MP -MF .deps/myobject.Tpo -c -o myobject.o myobject.c
mv -f .deps/myobject.Tpo .deps/myobject.Po
gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o
main.o: In function `main':
/home/aj/Desktop/GObjectTest/src/main.c:9: undefined reference to `g_type_init'
/home/aj/Desktop/GObjectTest/src/main.c:10: undefined reference to `g_type_create_instance'
myobject.o: In function `a_get_type':
/home/aj/Desktop/GObjectTest/src/myobject.c:19: undefined reference to `g_type_register_static'
collect2: ld returned 1 exit status
make[2]: *** [GObjectTest] Error 1
make[2]: Leaving directory `/home/aj/Desktop/GObjectTest/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/aj/Desktop/GObjectTest'
make: *** [all] Error 2
Here is the interesting part: replace gcc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 -o GObjectTest main.o myobject.o with gcc -o GObjectTest main.o myobject.o -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -lgobject-2.0 -lglib-2.0 and it works.

Related

Learn c the hard way ex29 compiling/linking problem

I have a github repo representing my exercise folder. Upon running make all the compiler throws error messages saying (Ubuntu):
cc -g -O2 -Wall -Wextra -Isrc -DNDEBUG -fPIC -c -o src/libex29.o src/libex29.c
src/libex29.c: In function ‘fail_on_purpose’:
src/libex29.c:36:33: warning: unused parameter ‘msg’ [-Wunused-parameter]
int fail_on_purpose(const char* msg)
^~~
ar rcs build/libex29.a src/libex29.o
ranlib build/libex29.a
cc -shared -o build/libex29.so src/libex29.o
cc -g -Wall -Wextra -Isrc test/ex29_test.c -o test/ex29_test
/tmp/cc7dbqDt.o: In function `main':
/home/givi/Desktop/lcthw_dir/29/test/ex29_test.c:21: undefined reference to `dlopen'
/home/givi/Desktop/lcthw_dir/29/test/ex29_test.c:22: undefined reference to `dlerror'
/home/givi/Desktop/lcthw_dir/29/test/ex29_test.c:25: undefined reference to `dlsym'
/home/givi/Desktop/lcthw_dir/29/test/ex29_test.c:26: undefined reference to `dlerror'
/home/givi/Desktop/lcthw_dir/29/test/ex29_test.c:33: undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'test/ex29_test' failed
make: *** [test/ex29_test] Error 1
i spent quite a lot trying to figure out how to fix undefined references. dlfcn.h is included, everything seems to be ok. Am i missing something? Please help
You must add following option when linking code using dlopen(3) :
-ldl
Here is a demo for Ubuntu 18:
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
$ cat dl.c
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
void *r;
r = dlopen("", RTLD_LAZY);
if (r != NULL)
printf("r is not null \n");
return 0;
}
$ gcc -o dl -Wall -pedantic -std=c11 dl.c -ldl
$ echo $?
0
Here is a very simple Makefile(note position of -ldl) and related make commands:
$ cat Makefile
CFLAGS=-g -O2 -Wall -Wextra -Isrc -DNDEBUG $(OPTFLAGS) $(OPTLIBS)
dl.o :dl.c
$(CC) -c $< $(CFLAGS)
dl :dl.o
$(CC) -o $# $^ $(CFLAGS) -ldl
clean :
rm -f dl dl.o
$ make clean
rm -f dl dl.o
$ make dl
cc -c dl.c -g -O2 -Wall -Wextra -Isrc -DNDEBUG
dl.c: In function ‘main’:
dl.c:5:14: warning: unused parameter ‘argc’ [-Wunused-parameter]
int main(int argc, char **argv)
^~~~
dl.c:5:27: warning: unused parameter ‘argv’ [-Wunused-parameter]
int main(int argc, char **argv)
^~~~
cc -o dl dl.o -g -O2 -Wall -Wextra -Isrc -DNDEBUG -ldl
$ ./dl
r is not null
Usually the references you're missing can be resolved by adding linker flag -ldl.
You didn't mention which operating system you're using.
In case you're on Windows you'll need this library: https://github.com/dlfcn-win32/dlfcn-win32

Undefined reference to main, makefile

I have a simple structure as:
sample2Make$ ls
ADD DIV inc_print.h main.c makefile multiplication.o printer.o response.o subtraction.o addition.o division.o inc_resp.h main.o MUL printer.c response.c SUB
where ADD, DIV, SUB, MUL are subdirectories containing a source file for the operation and a header file. The makefile is:
app: addition.o subtraction.o multiplication.o division.o response.o
gcc -o app response.o addition.o subtraction.o multiplication.o division.o
response.o: inc_resp.h inc_print.h response.c printer.c main.c
gcc -c response.c printer.c main.c
addition.o: ADD/inc_add.h ADD/addition.c
gcc -c ADD/addition.c
subtraction.o: SUB/inc_sub.h SUB/subtraction.c
gcc -c SUB/subtraction.c
multiplication.o: MUL/inc_mul.h MUL/multiplication.c
gcc -c MUL/multiplication.c
division.o: DIV/inc_div.h DIV/division.c
gcc -c DIV/division.c
The header files just have declarations of their respective functions. Now after writing a command:
sample2Make$ make -f makefile
The output I am getting is:
gcc -c ADD/addition.c
gcc -c SUB/subtraction.c
gcc -c MUL/multiplication.c
gcc -c DIV/division.c
gcc -c response.c printer.c main.c
gcc -o app addition.o subtraction.o multiplication.o division.o response.o
/usr/lib/gcc/i686-linux-gnu/4.9/../../../i386-linux-gnu/crt1.o: In function `_start':
/build/buildd/glibc-2.21/csu/../sysdeps/i386/start.S:111: undefined reference to `main'
collect2: error: ld returned 1 exit status
makefile:3: recipe for target 'app' failed
make: *** [app] Error 1
You missed to include printer.o and main.o in the final compilation statement, and due to the missing reference to the main(), your compiler screams.
Your final statement should look like
gcc -o app addition.o subtraction.o multiplication.o division.o response.o printer.o main.o

Not able to link Mersenne twister inside Freeswitch module

I am trying to add Mersenne twister random library inside a Freeswitch module but when I try to compile and link I get:
making all mod_svbilling
Compiling /usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/mod_svbilling.c...
Compiling /usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/mod_svbilling.c ...
Creating mod_svbilling.so...
mtwist.o: In function `mts_lrand':
mtwist.c:(.text+0x0): multiple definition of `mts_lrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:417: first defined here
mtwist.o: In function `mts_llrand':
mtwist.c:(.text+0x6d): multiple definition of `mts_llrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:446: first defined here
mtwist.o: In function `mts_drand':
mtwist.c:(.text+0x189): multiple definition of `mts_drand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:488: first defined here
mtwist.o: In function `mts_ldrand':
mtwist.c:(.text+0x210): multiple definition of `mts_ldrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:507: first defined here
mtwist.o: In function `mt_lrand':
mtwist.c:(.text+0x349): multiple definition of `mt_lrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:555: first defined here
mtwist.o: In function `mt_llrand':
mtwist.c:(.text+0x3d7): multiple definition of `mt_llrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:575: first defined here
mtwist.o: In function `mt_drand':
mtwist.c:(.text+0x55c): multiple definition of `mt_drand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:618: first defined here
mtwist.o: In function `mt_ldrand':
mtwist.c:(.text+0x604): multiple definition of `mt_ldrand'
.libs/mod_svbilling.o:/usr/src/freeswitch-1.2.12/src/mod/applications/mod_svbilling/./mtwist/mtwist.h:636: first defined here
collect2: ld returned 1 exit status
gcc -I. -I./svblic -I./mtwist -fPIC -DVERSION= -DSVN_REV=108M -I/usr/src/freeswitch-1.2.12/libs/curl/include -I/usr/src/freeswitch-1.2.12/src/include -I/usr/src/freeswitch-1.2.12/src/include -I/usr/src/freeswitch-1.2.12/libs/libteletone/src -I/usr/src/freeswitch-1.2.12/libs/stfu -fPIC -Werror -fvisibility=hidden -DSWITCH_API_VISIBILITY=1 -DHAVE_VISIBILITY=1 -g -ggdb -DHAVE_OPENSSL -g -O2 -Wall -std=c99 -pedantic -Wdeclaration-after-statement -D_GNU_SOURCE -shared -o .libs/mod_svbilling.so -shared -Wl,-x .libs/mod_svbilling.o aes.o lic.o md5.o sysinfo.o mtwist.o -lsqlite3 -lm /usr/src/freeswitch-1.2.12/.libs/libfreeswitch.so -L/usr/src/freeswitch-1.2.12/libs/apr-util/xml/expat/lib -lpq /usr/src/freeswitch-1.2.12/libs/apr-util/xml/expat/lib/.libs/libexpat.a /usr/src/freeswitch-1.2.12/libs/apr/.libs/libapr-1.a -lpthread -L/usr/src/freeswitch-1.2.12/libs/srtp -lcrypt -lrt -lssl -lcrypto -ldl -lz -lncurses -ljpeg -lodbc -Wl,--rpath -Wl,/usr/local/freeswitch/lib -Wl,--rpath -Wl,/usr/local/freeswitch/mod
make[4]: *** [mod_svbilling.so] Error 1
make[3]: *** [all] Error 1
make[2]: *** [mod_svbilling-all] Error 1
make[1]: *** [mod_svbilling] Error 2
make: *** [mod_svbilling] Error 2
Makefile I am using looks like:
BASE=../../../..
SVN_REV=$(shell svnversion -n .)
SVB_LIB_FLAGS = -lm -lpthread -lsqlite3
SVB_CFLAGS = -I. -I./svblic -I./mtwist -fPIC
MOD_CFLAGS=$(SVB_LIB_FLAGS) $(SVB_CFLAGS) -DVERSION=$(VERSION) -DSVN_REV=$(SVN_REV)
LOCAL_OBJS=aes.o lic.o md5.o sysinfo.o mtwist.o
local_depend: $(LOCAL_OBJS)
sysinfo.o: ./svblic/sysinfo.c
gcc $(SVB_CFLAGS) -c ./svblic/sysinfo.c
aes.o: ./svblic/aes.c
gcc $(SVB_CFLAGS) -c ./svblic/aes.c
md5.o: ./svblic/md5.c
gcc $(SVB_CFLAGS) -c ./svblic/md5.c
lic.o: ./svblic/lic.c
gcc $(SVB_CFLAGS) -c ./svblic/lic.c
mtwist.o: ./mtwist/mtwist.c
gcc $(SVB_CFLAGS) -c ./mtwist/mtwist.c
include $(BASE)/build/modmake.rules
I only added following header to my module source code:
#include "./mtwist/mtwist.h"
I don't know why it sais those functions are already defined. mtwist.h has one define in order to avoid redefine those functions
Any idea?
Regards

Error while compiling SVGA source

I am trying to compile SVGA source to build for shared-library object.
while compiling i am getting this error
make[1]: Entering directory `/home/manmatha/Downloads/svgalib-1.9.25/utils'
gcc -I../include -I. -MM ../utils/restorefont.c ../utils/convfont.c ../utils/restoretextmode.c ../utils/restorepalette.c ../utils/dumpreg.c >.depend
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -c -o restorefont.o restorefont.c
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o restorefont restorefont.o -lvga -lm
chmod 4755 restorefont
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -c -o convfont.o convfont.c
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o convfont convfont.o -lvga -lm
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -c -o restoretextmode.o restoretextmode.c
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o restoretextmode restoretextmode.o -lvga -lm
chmod 4755 restoretextmode
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -c -o restorepalette.o restorepalette.c
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o restorepalette restorepalette.o -lvga -lm
chmod 4755 restorepalette
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -c -o dumpreg.o dumpreg.c
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o dumpreg dumpreg.o -lvga -lm
chmod 4755 dumpreg
cc -Wall -Wstrict-prototypes -fomit-frame-pointer -O2 -fno-strength-reduce -pipe -I../include -L../sharedlib -s -o gtfcalc -DTESTING_GTF gtf/gtfcalc.c -lvga -lm
gtf/gtfcalc.c:67: error: static declaration of ‘round’ follows non-static declaration
make[1]: *** [gtfcalc] Error 1
make[1]: Leaving directory `/home/manmatha/Downloads/svgalib-1.9.25/utils'
make: *** [textutils] Error 2
Edit::Yes the patch works..But the compilation encounters the next error while compiling the svga_helper.ko module
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:1:26: error: linux/config.h: No such file or directory
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:20:35: error: linux/devfs_fs_kernel.h: No such file or directory
In file included from /home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:42:
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/kernel26compat.h: In function ‘devfs_unregister_chrdev’:
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/kernel26compat.h:80: error: void value not ignored as it ought to be
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c: In function ‘svgalib_helper_ioctl’:
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:237: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:242: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:247: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:252: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:258: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:264: warning: cast to pointer from integer of different size
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:358: error: ‘SA_SHIRQ’ undeclared (first use in this function)
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:358: error: (Each undeclared identifier is reported only once
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:358: error: for each function it appears in.)
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:358: warning: passing argument 2 of ‘request_irq’ from incompatible pointer type
include/linux/interrupt.h:123: note: expected ‘irq_handler_t’ but argument is of type ‘enum irqreturn_t (*)(int, void *, struct pt_regs *)’
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c: In function ‘svgalib_helper_open’:
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:446: error: ‘SA_SHIRQ’ undeclared (first use in this function)
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:446: warning: passing argument 2 of ‘request_irq’ from incompatible pointer type
include/linux/interrupt.h:123: note: expected ‘irq_handler_t’ but argument is of type ‘enum irqreturn_t (*)(int, void *, struct pt_regs *)’
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c: In function ‘init_module’:
/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.c:651: error: implicit declaration of function ‘class_device_create’
make[3]: *** [/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper/main.o] Error 1
make[2]: *** [_module_/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper] Error 2
make[2]: Leaving directory `/usr/src/kernels/2.6.32-358.0.1.el6.x86_64'
make[1]: *** [default] Error 2
make[1]: Leaving directory `/home/manmatha/Downloads/svgalib-1.9.25/kernel/svgalib_helper'
make: *** [installmodule] Error 2
I think you want to go for a newer version of svgalib. 1.4.3 is pretty old and no longer maintained. If I remember correctly it needed to be patched to work with newer compilers as well.
Try one of the 1.9.x versions from http://svgalib.org/
For later versions, if you get the error:
error: static declaration of 'round' follows non-static declaration
Apply the following patch:
--- svgalib-1.9.25/utils/gtf/gtfcalc.c
+++ svgalib-1.9.25/utils/gtf/gtfcalc.c
## -68,5 +68,5 ##
-static double round(double v)
+double round(double v)
{
return floor(v + 0.5);
}
EDIT:
With your latest compile issue in the svga_helper.ko module, set the NO_HELPER variable to disable building svga_helper.ko. config.h etc. were removed form more recent kernels. From the Readme:
There is a compile time option to return to old behaviour, of using
root privileges to access /dev/mem, instead of svgalib helper. To
compile for this select the NO_HELPER option in Makefile.cfg.

Getting compilation errors whn included a third party library

#include<stdio.h>
#include "flite.h"
cst_voice *register_cmu_us_kal();
int main()
{
cst_voice *v;
cst_wave *w;
char *text = "Hello world programming";
//Initialising the flite variables used
flite_init();
w = new_wave();
v = register_cmu_us_kal(NULL);
flite_text_to_speech(text,v,"hello_wave");
if(cst_wave_load_riff(w,"hello_wave")!=CST_OK_FORMAT){
printf("\nCompare_wave:Can read file or wrong format!\n");
}
else{
play_wave(w);
}
return 0;
}
Makefile
all:compile \
./compile
compile:eg1.o
gcc -o $# eg1.o
eg1.o:eg1.c $(LIBS_DIR) $(INC_DIR) $(LIBS)
gcc -c $<
LIBS_DIR = -L /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -I /home/b/flite-1.4-relase/include
LIBS = -lflite_cmu_us_slt -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish
INCLUDE:
clean:
rm -f *.o
I tried by giving he library and header file paths as LIBS_DIR = ../build/i386-linux-gnu/lib and INC_DIR = ../include
I tried the folowing c program by including a third party library. This program an a makefile is located in b\flite-1.4-release\Learnin_though_example folder. Th flite libraries are located in b\flite-1.4-release\build\i386-linux-gnu\lib and the header files are in b\flite-1.4-release\include .
I assume that i have given the makefile th correct path to search for the files. But its not identifyin it and i'm gettin an error as,
make clean all
rm -f *.o
gcc -c eg1.c
eg1.c:2:19: error: flite.h: No such file or directory
eg1.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
eg1.c: In function ‘main’:
eg1.c:6: error: ‘cst_voice’ undeclared (first use in this function)
eg1.c:6: error: (Each undeclared identifier is reported only once
eg1.c:6: error: for each function it appears in.)
eg1.c:6: error: ‘v’ undeclared (first use in this function)
eg1.c:7: error: ‘cst_wave’ undeclared (first use in this function)
eg1.c:7: error: ‘w’ undeclared (first use in this function)
eg1.c:17: error: ‘CST_OK_FORMAT’ undeclared (first use in this function)
make: *** [eg1.o] Error 1
Please help me understand what is the mistake i'm doing
EDITED:
I modiied th makefile as per matt's guidance:
all:compile
compile:eg1.o
gcc $(INC_DIR) $(LIB_DIR) -o $# $^ $(LIBS)
eg1.o:eg1.c
gcc $(INC_DIR) -o $# -c $^
LIBS_DIR = -L../build/i386-linux-gnu/lib
INC_DIR = -I../include
LIBS = -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish -lflite_cmu_us_slt
clean:
rm -f *.o
but i'm getting ifferent error whn compiled with the command "make clean all" as,
rm -f *.o
gcc -I../include -o eg1.o -c eg1.c
gcc -I../include -o compile eg1.o -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish -lflite_cmu_us_slt
/usr/bin/ld: cannot find -lflite
collect2: ld returned 1 exit status
make: *** [compile] Error 1
EDITED:
rm -f *.o
gcc -I../include -o eg1.o -c eg1.c
gcc -I../include -L../build/i386-linux-gnu/lib -o compile eg1.o -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_usenglish -lflite_cmu_us_slt -lflite_cmu_us_rms
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `sin'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `exp'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `sqrt'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `log'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `fmod'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `pow'
Your makefile is, I'm afraid to say, completely broken.
The basic Makefile syntax is:
target: pre-requisite(s)
<tab>Stuff to do to build target from pre-reqs (if required)
So this is wrong, eg1.o can't be a pre-requisite for building itself.
compile:eg1.o
gcc -o eg1.o
You should have:
eg1.o: eg1.c
gcc $(INC_DIR) -o $# -c $^
($# is the target, $^ all the pre-reqs.)
Then you can:
myexe: eg1.o
gcc $(INC_DIR) $(LIBS_DIR) -o $# $^ $(LIBS)
This will produce myexe from eg1.o. And your all rule should be all: myexe, with no recipe (no commands), and at the top as you have it.
Then you've got your include directories and library directories mixed up. -I is for include paths, -L for library paths.
Place your variable definitions before the rules, that's more common/usual. And don't put a space between -L/-I and the path that follows it.
The include directories to search is specified by -I flag, not -L.
Change:
LIBS_DIR = -I /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -L /home/b/flite-1.4-relase/include
to:
LIBS_DIR = -L /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -I /home/b/flite-1.4-relase/include

Resources