入门编译错误WHN包括第三方库 [英] Getting compilation errors whn included a third party library

查看:237
本文介绍了入门编译错误WHN包括第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 #包括LT&;&stdio.h中GT;
#包括flite.h
cst_voice * register_cmu_us_kal();
诠释的main()
{
 cst_voice * V;
 cst_wave *宽;
 字符*文字=世界,你好规划; //正在初始化所使用的变量FLITE
 flite_init();
 W = new_wave(); V = register_cmu_us_kal(NULL);
 flite_text_to_speech(文字,V,hello_wave); 如果(cst_wave_load_riff(重量,hello_wave)!= CST_OK_FORMAT){
  的printf(\\ nCompare_wave:可以读文件或格式错误\\ n);
 }
 其他{
  play_wave(重量);
 }
 返回0;
}

的Makefile

 所有:编译\\
  ./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
包括:
清洁:
  RM -f *的.o
我试图通过给他库和头文件路径为LIBS_DIR = ../build/i386-linux-gnu/lib和INC_DIR = ../include

我通过包括第三方库尝试了如下因素C程序。该程序的一个makefile坐落在B \\ FLITE-1.4版本\\ Learnin_though_example文件夹中。日FLITE库位于在B \\ FLITE-1.4版本\\版本\\ I386-Linux的GNU \\ lib和头文件是在B \\ FLITE-1.4版本\\ include中。

我认为我已经给出了第makefile文件正确的路径来搜索文件。但它不是identifyin它,我想趁自己一个错误,

 使清洁所有
RM -f *的.o
GCC -c eg1.c
eg1.c:2:19:错误:flite.h:没有这样的文件或目录
eg1.c:3:错误:预期€〜= A€™,â€〜,’,â€〜;’,â€~asm’或â€~__attribute__’前€〜 *一个€™令牌
eg1.c:在功能上€~main’:
eg1.c:6:错误:€~cst_voice’未申报(在一次使用此功能)
eg1.c:6:错误:(每个未声明的标识符报道只有一次
eg1.c:6:错误:它出现在每个功能)
eg1.c:6:错误:€~v’未申报(在一次使用此功能)
eg1.c:7:错误:€~cst_wave’未申报(在一次使用此功能)
eg1.c:7:错误:€~w’未申报(在一次使用此功能)
eg1.c:17:错误:€~CST_OK_FORMAT’未声明(第一次使用此功能使用)
使:*** [eg1.o]错误1

请帮助我了解什么是我做的错误

编辑:

我modiied日的makefile根据马特的指导意见:

 所有:编译
编译:eg1.o
  GCC $(INC_DIR)$(LIB_DIR)-o $ @ $ ^ $(LIBS)
eg1.o:eg1.c
  GCC $(INC_DIR)-o $ @ -c $ ^
LIBS_DIR = -L ../编译/ I386-Linux的GNU / lib目录
INC_DIR = -I ../包括
LIBS = -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish -lflite_cmu_us_slt
清洁:
  RM -f *的.o

但我得到ifferent错误WHN用命令编译使清洁所有一样,

  RM -f *的.o
GCC -I ../包括-o eg1.o -c eg1.c
GCC -I ../包括-o编译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 /斌/劳工处:找不到-lflite
collect2:劳工处返回1退出状态
使:*** [编译]错误1

编辑:

  RM -f *的.o
GCC -I ../包括-o eg1.o -c eg1.c
GCC -I ../包括-L ../建立/ I386-Linux的GNU / lib目录-o编译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:未定义引用'罪'
../build/i386-linux-gnu/lib/libflite.so:未定义参考`EXP
../build/i386-linux-gnu/lib/libflite.so:未定义引用'开方'
../build/i386-linux-gnu/lib/libflite.so:未定义引用'登录'
../build/i386-linux-gnu/lib/libflite.so:未定义的引用`FMOD
../build/i386-linux-gnu/lib/libflite.so:未定义引用'战俘'


解决方案

您的Makefile,我怕说了,彻底打破。

基本Makefile的语法是:

 目标:pre-必要的(S)
<标签>的东西做从pre-请求数构建目标(如果需要)

所以,这是不对的, eg1.o 不能是pre-必要的建设本身。

 编译:eg1.o
  GCC -o eg1.o

您应该有:

  eg1.o:eg1.c
  GCC $(INC_DIR)-o $ @ -c $ ^

$ @ 是目标, $ ^ 所有pre-请求数。)

然后,您可以:

  myexe:eg1.o
  GCC $(INC_DIR)$(LIBS_DIR)-o $ @ $ ^ $(LIBS)

这将产生 myexe eg1.o 。而你的所有规则应该是所有:myexe ,无配方(没有命令),并在顶部,你拥有它。

然后,你有你的包括混合起来目录和库目录。 -I 是包括路径, -L 的库路径。

将变量定义的规则之前,这是比较常见的/如常。不要把 -L / -I 和它后面的路径的空间。

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

这篇关于入门编译错误WHN包括第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆