【问题标题】:Cannot comiple .c because it cannot find .h file无法编译 .c,因为它找不到 .h 文件
【发布时间】:2021-09-24 03:05:35
【问题描述】:

我在 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 还是很陌生,因为我仍在学习基础知识,但如果有人可以帮助我,我将不胜感激. 提前致谢!

【问题讨论】:

  • 您的系统上安装了libvosk.so 的位置(或者可能是libvosk.a)?通过find / -name "libvosk*" 2&gt; /dev/null 找到它
  • @Mathieu 然后gcc test_vosk.c -o test_vosk 而不是gcc test_cosk.c /usr/lib/libvosk.so -o test_vosk 应该给gcc 特定的位置

标签: linux kaldi vosk


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-25
    相关资源
    最近更新 更多