gpt4 book ai didi

c - 包含第三方库时出现编译错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:14:53 25 4
gpt4 key购买 nike

#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 文件夹中。 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'

最佳答案

我不敢说,您的 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)

这将从 eg1.o 生成 myexe。您的 all 规则应该是 all: myexe,没有配方(没有命令),并且在您拥有的顶部。

那么您的包含目录和库目录就混淆了。 -I 用于包含路径,-L 用于库路径。

将您的变量定义放在规则之前,这更常见/通常。并且不要在 -L/-I 和它后面的路径之间放置空格。

关于c - 包含第三方库时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9247661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com