Search code examples
clinuxmakefilelibav

"undefined reference" error messages when trying to compile spdif-loop


I'm trying to compile spdif-loop on my machine running Ubuntu 14.04. It says on the GitHub page that the requirements are ffmpeg or libav and libao. I have only very little experience with this, but I thought I'd look at the make file for more details and found this line:

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

My guess was that I can install the necessary dependencies like this:

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.

When I try to compile I get the following result:

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

More guesswork trying to find or fix the issue:

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);

So the header file and a function within that file exists, I guess?

I tried searching around, I found a few similar questions with more complex make files for Android projects, I think that is the wrong direction. I also found this note in the FAQ, but I thought this is a C program not C++. And I just looked at similar questions suggested to me.

As I said, I have almost no experience, can you tell me please what I am doing wrong, what I am missing or what needs to be added to make this to build properly?

I also tried

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

and

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

in the make file, without success or progress.


Solution

  • Try with the following 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}
    

    On my Ubuntu 14.xx it compiles!