c - 尝试编译 spdif-loop 时出现 "undefined reference"错误消息

标签 c linux makefile libav

我正在尝试编译 spdif-loop在我运行 Ubuntu 14.04 的机器上。它在 GitHub 页面上说要求是 ffmpeglibavlibao。我对此只有很少的经验,但我想我会查看 make 文件以获取更多详细信息并找到这一行:

LDFLAGS+=       -lavcodec -lavformat -lavdevice -lavutil -lao -lm

我的猜测是我可以像这样安装必要的依赖项:

sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavutil-dev libao-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libao-dev is already the newest version.
libavcodec-dev is already the newest version.
libavdevice-dev is already the newest version.
libavformat-dev is already the newest version.
libavutil-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 8 not upgraded.

当我尝试编译时,我得到以下结果:

livewire@za20:~/Projects/Software/spdif-loop$ make
cc -Wall -std=c99 -g  -lavcodec -lavformat -lavdevice -lavutil -lao -lm  spdif-loop.c   -o spdif-loop
/tmp/ccGCH40C.o: In function `alsa_reader':
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:41: undefined reference to `av_read_frame'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:80: undefined reference to `av_free_packet'
/tmp/ccGCH40C.o: In function `probe_codec':
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:91: undefined reference to `av_init_packet'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:92: undefined reference to `av_read_frame'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:95: undefined reference to `av_free_packet'
/tmp/ccGCH40C.o: In function `open_output':
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:118: undefined reference to `ao_open_live'
/tmp/ccGCH40C.o: In function `test_audio_out':
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:151: undefined reference to `cos'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:160: undefined reference to `ao_play'
/tmp/ccGCH40C.o: In function `main':
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:209: undefined reference to `av_register_all'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:210: undefined reference to `avcodec_register_all'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:211: undefined reference to `avdevice_register_all'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:212: undefined reference to `ao_initialize'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:216: undefined reference to `ao_append_option'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:220: undefined reference to `ao_default_driver_id'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:222: undefined reference to `ao_driver_id'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:232: undefined reference to `av_find_input_format'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:236: undefined reference to `av_find_input_format'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:241: undefined reference to `av_malloc'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:253: undefined reference to `avformat_close_input'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:255: undefined reference to `avformat_close_input'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:257: undefined reference to `ao_close'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:265: undefined reference to `avformat_alloc_context'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:269: undefined reference to `avformat_open_input'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:275: undefined reference to `av_init_packet'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:277: undefined reference to `avio_alloc_context'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:281: undefined reference to `avformat_open_input'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:290: undefined reference to `avcodec_find_decoder'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:296: undefined reference to `avcodec_alloc_context3'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:300: undefined reference to `avcodec_open2'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:304: undefined reference to `av_init_packet'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:311: undefined reference to `av_free_packet'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:312: undefined reference to `av_read_frame'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:320: undefined reference to `avcodec_get_frame_defaults'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:322: undefined reference to `avcodec_decode_audio4'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:339: undefined reference to `av_get_bytes_per_sample'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:346: undefined reference to `av_samples_get_buffer_size'
/home/livewire/Projects/Software/spdif-loop/spdif-loop.c:370: undefined reference to `ao_play'
collect2: error: ld returned 1 exit status
make: *** [spdif-loop] Error 1

尝试查找或修复问题的更多猜测:

livewire@za20:~/Projects/Software/spdif-loop$ grep av_read_frame /usr/include/libavformat/*
/usr/include/libavformat/avformat.h: * avformat_open_input() function for opening a file, av_read_frame() for
/usr/include/libavformat/avformat.h: * av_read_frame() on it. Each call, if successful, will return an AVPacket
/usr/include/libavformat/avformat.h: * until the next av_read_frame() call or closing the file. If the caller
/usr/include/libavformat/avformat.h:    /* av_read_frame() support */
/usr/include/libavformat/avformat.h:     * appear in av_read_frame().
/usr/include/libavformat/avformat.h: * Use av_read_frame() instead.
/usr/include/libavformat/avformat.h: * av_read_frame() or until av_close_input_file(). Otherwise the packet is valid
/usr/include/libavformat/avformat.h:int av_read_frame(AVFormatContext *s, AVPacket *pkt);

所以头文件和该文件中的函数存在,我猜?

我尝试四处搜索,发现了一些类似的问题,其中包含针对 Android 项目的更复杂的 make 文件,我认为这是错误的方向。我还找到了this note in the FAQ ,但我认为这是一个 C 程序而不是 C++。我只是查看了向我提出的类似问题。

正如我所说,我几乎没有经验,您能告诉我我做错了什么,我缺少什么或者需要添加什么才能正确构建吗?

我也试过

LDFLAGS+=       -lavcodec -lavformat -lavdevice -lavutil -lao -lm -L/usr/include/libavformat

LDFLAGS+=       -lavcodec -lavformat -lavdevice -lavutil -lao -lm -L/usr/lib/x86_64-linux-gnu

在 make 文件中,没有成功或进展。

最佳答案

尝试使用以下 Makefile:

PROG=   spdif-loop

CFLAGS+=        -Wall -std=c99 -g
LDFLAGS+=       -lavcodec -lavformat -lavdevice -lavutil -lao -lm

all: ${PROG}

$(PROG): $(PROG).c
        cc $(CFLAGS) $(PROG).c $(LDFLAGS) -o $(PROG)
clean:
        -rm -f ${PROG}

在我的 Ubuntu 14.xx 上它可以编译!

关于c - 尝试编译 spdif-loop 时出现 "undefined reference"错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29719970/

相关文章:

linux - 如何用shell脚本读取变量中的多个值

c++ - GCC 依赖跟踪 : Is -M better than -MM?

c - 在 Windows 10 上构建此代码的正确方法是什么?

将 int 转换为 char C 公式

linux - Python 不接受 crontab

linux - Bash 内置哈希和命令搜索

c++ - 如何为许多自包含 cpp 文件的文件夹创建 */* ?

c - SIGTERM 信号处理程序未打印到控制台

java - 从 C 更新嵌套的 java 对象

c - Prim 的 MST 算法,C 中的邻接表实现