#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;
}
生成文件
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
我通过包含第三方库尝试了以下c程序。该程序和一个makefile位于b \ flite-1.4-release \ Learnin_though_example文件夹中。 th flite库位于b \ flite-1.4-release \ build \ i386-linux-gnu \ lib中,头文件位于b \ flite-1.4-release \ include。
我假设我已经为makefile提供了搜索文件的正确路径。但它没有识别它,我得到一个错误,
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
请帮助我理解我正在做的错误
编辑:
我根据matt的指导修改了makefile:
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
但是我得到了使用“make clean all”命令编译的不一致错误,
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
编辑:
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'
答案 0 :(得分:2)
你的makefile是,我不敢说完全坏了。
基本的Makefile语法是:
target: pre-requisite(s)
<tab>Stuff to do to build target from pre-reqs (if required)
所以这是错误的,eg1.o
不能成为建立自己的先决条件。
compile:eg1.o
gcc -o eg1.o
你应该:
eg1.o: eg1.c
gcc $(INC_DIR) -o $@ -c $^
($@
是目标,$^
所有预先要求。)
然后你可以:
myexe: eg1.o
gcc $(INC_DIR) $(LIBS_DIR) -o $@ $^ $(LIBS)
这将从myexe
生成eg1.o
。并且您的all
规则应该是all: myexe
,没有配方(没有命令),并且在您拥有它时位于顶部。
然后你的include目录和库目录已经混淆了。 -I
适用于包含路径,库路径为-L
。
将变量定义放在规则之前,这是更常见/通常的。并且不要在-L
/ -I
和其后的路径之间留出空格。
答案 1 :(得分:1)
要搜索的include directories由-I
标志指定,而不是-L
。
变化:
LIBS_DIR = -I /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -L /home/b/flite-1.4-relase/include
为:
LIBS_DIR = -L /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -I /home/b/flite-1.4-relase/include