c/c++语言开发共享获取包含第三方库的编译错误

#include #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 

我通过包含第三方库来尝试下面的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”命令编译的ifferent错误,

 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' 

    你害怕说,你的makefile完全崩溃了。

    基本的Makefile语法是:

     target: pre-requisite(s) 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和它-I的路径之间放置一个空格。

    要搜索的include目录由-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 

      以上就是c/c++开发分享获取包含第三方库的编译错误相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/522827.html

      (0)
      上一篇 2020年12月11日
      下一篇 2020年12月11日

      精彩推荐