linux - 无法编译 .c,因为找不到 .h 文件

标签 linux kaldi vosk

我使用的是 ubuntu 18.04,我正在尝试编译一个 .c 文件,该文件带有我正在使用的 API,名为 vosk 。 问题是 python 代码工作没有任何问题,但如果我尝试

gcc test_vosk.c -o test_vosk

他们提供的用于运行 API 的 .c 文件给了我这个错误:

test_vosk.c:1:10: fatal error: vosk_api.h: No such file or directory
 #include <vosk_api.h>
          ^~~~~~~~~~~~
compilation terminated.

所以我尝试make Makefile,它位于test_vosk.c文件的同一目录中,但它给了我:

g++ test_vosk.o -o test_vosk -L../src -lvosk -ldl -lpthread -Wl,-rpath=../src
/usr/bin/ld: cannot find -lvosk
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'test_vosk' failed
make: *** [test_vosk] Error 1

这是有道理的,因为目录/usr/bin/ld 实际上并不存在于我的机器上。 然后我尝试将 vosk_api.h 文件从其目录(该目录是 test_vosk.c 所在目录的父目录)移动到 test_vosk.c 文件的同一目录,并更改

#include <vosk_api.h>

进入

#include "vosk_api.h"

现在如果我再次编译

gcc test_vosk.c -o test_vosk

它给了我:

/tmp/cct4dVqp.o: In function `main':
test_vosk.c:(.text+0x22): undefined reference to `vosk_model_new'
test_vosk.c:(.text+0x40): undefined reference to `vosk_recognizer_new'
test_vosk.c:(.text+0xc7): undefined reference to `vosk_recognizer_accept_waveform'
test_vosk.c:(.text+0xe5): undefined reference to `vosk_recognizer_result'
test_vosk.c:(.text+0xfe): undefined reference to `vosk_recognizer_partial_result'
test_vosk.c:(.text+0x12c): undefined reference to `vosk_recognizer_final_result'
test_vosk.c:(.text+0x143): undefined reference to `vosk_recognizer_free'
test_vosk.c:(.text+0x152): undefined reference to `vosk_model_free'
collect2: error: ld returned 1 exit status

我已经被困在这个问题上好几天了,我真的不知道该去哪里,我对 Linux 还很陌生,因为我仍在学习基础知识,但如果有人可以帮助我,我将非常感激。 提前致谢!

最佳答案

谢谢两位的解答!!! 所以 test_vosk.c 无法编译,因为它找不到 libvosk.so 所以我找到了 prebuilt binary它并把它放在/lib 目录中,然后从 makefile 运行 make ,该文件位于编译它的 test_vosk.c 的同一目录中...... 但现在它无法运行,这让我很生气,因为同一个脚本在 python 中运行没有问题。 我将打开一个新问题,以便这个问题得到解决。

关于linux - 无法编译 .c,因为找不到 .h 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68389868/

相关文章:

linux - 64 位 Linux 中的交换空间

linux - 源中的上下文切换

linux - 如果发生转换错误,如何返回到应用程序而不检查pam中的其他方法

unity-game-engine - Unity 中的 Vosk (Kaldi) 离线语音识别

java - 使用java中的麦克风通过VOSK进行语音识别

linux - 远程端口转发或代理转发

python-3.x - 将 .wav 音频文件设置复制到新的 .wav 文件

linux - 使用 Cygwin 安装 Kaldi,zlib 出错

python - 如何使用 Vosk 离线语音识别(或任何其他快速离线语音识别器)为虚拟助手设置唤醒词