silicontrip / lavtools

mjpeg utils and avcodec frame based video editing tools and ffmpeg filters
15 stars 3 forks source link

'-Wl,--as-needed' breaks build #15

Open Nikoli opened 10 years ago

Nikoli commented 10 years ago

A lot if not all targets fail to build with '-Wl,--as-needed', without they build fine:

$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe -I/usr/include/mjpegtools -I/usr/include/freetype2 -D__STDC_CONSTANT_MACROS  -c -o libav-bitrate.o libav-bitrate.c
$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe -I/usr/include/mjpegtools -I/usr/include/freetype2 -D__STDC_CONSTANT_MACROS  -c -o progress.o progress.c
progress.c: In function ‘progress_loadBar’:
progress.c:129:2: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 3 has type ‘off_t’ [-Wformat]
$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -lswscale -lavcodec -lavformat -lavutil -o libav-bitrate libav-bitrate.o progress.o
libav-bitrate.o: In function `main':
libav-bitrate.c:(.text.startup+0x242): undefined reference to `av_register_all'
libav-bitrate.c:(.text.startup+0x269): undefined reference to `avformat_open_input'
libav-bitrate.c:(.text.startup+0x280): undefined reference to `avformat_find_stream_info'
libav-bitrate.c:(.text.startup+0x29d): undefined reference to `av_dump_format'
libav-bitrate.c:(.text.startup+0x3aa): undefined reference to `avcodec_find_decoder'
libav-bitrate.c:(.text.startup+0x412): undefined reference to `avcodec_open2'
libav-bitrate.c:(.text.startup+0x41f): undefined reference to `avcodec_alloc_frame'
libav-bitrate.c:(.text.startup+0x4b3): undefined reference to `av_free_packet'
libav-bitrate.c:(.text.startup+0x4c8): undefined reference to `av_read_frame'
libav-bitrate.c:(.text.startup+0x55b): undefined reference to `avcodec_decode_video2'
libav-bitrate.c:(.text.startup+0x70e): undefined reference to `av_free'
libav-bitrate.c:(.text.startup+0x718): undefined reference to `avcodec_close'
libav-bitrate.c:(.text.startup+0x725): undefined reference to `avformat_close_input'
collect2: error: ld returned 1 exit status
$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe -Wl,--hash-style=gnu -Wl,-O1 -lswscale -lavcodec -lavformat -lavutil -o libav-bitrate libav-bitrate.o progress.o
Nikoli commented 10 years ago

I have libav-9.10

silicontrip commented 10 years ago

My gcc doesn't like the --as-needed option. So I cannot test any fix. It appears to be the order of the object files on the command line. I've changed the Makefile for libav-bitrate. I won't change the others until you can confirm that this resolves the issue.

Nikoli commented 10 years ago

I confirm that moving *.o options before LDFLAGS solves problem:

$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe libav-bitrate.c progress.o -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -lswscale -lavcodec -lavformat -lavutil -o libav-bitrate
$ objdump -p libav-bitrate|grep NEEDED|sort
  NEEDED               libavcodec.so.54
  NEEDED               libavformat.so.54
  NEEDED               libavutil.so.52
  NEEDED               libc.so.6

As you can see --as-needed works, it does not link to not used libswscale. Your changes to Makefile are partly wrong, because placing --as-needed after -l* is no-op:

$ x86_64-pc-linux-gnu-gcc -march=corei7-avx -O2 -pipe libav-bitrate.c progress.o -lswscale -lavcodec -lavformat -lavutil -ljpeg -lfftw3 -lz -Wl,--hash-style=gnu -Wl,-O1 -Wl,--as-needed -o libav-bitrate
$ objdump -p libav-bitrate|grep NEEDED|sort
  NEEDED               libavcodec.so.54
  NEEDED               libavformat.so.54
  NEEDED               libavutil.so.52
  NEEDED               libc.so.6
  NEEDED               libfftw3.so.3
  NEEDED               libjpeg.so.8
  NEEDED               libswscale.so.2
  NEEDED               libz.so.1
Nikoli commented 10 years ago

Building with --as-needed detected 2 other bugs: 1) yuvilace does not need fftw 2) opencv related flags should be OPENCV_LIBS=-lopencv_core -lopencv_highgui -lopencv_imgproc

Nikoli commented 10 years ago

Updated my pull request, this is now fixed in https://github.com/silicontrip/lavtools/pull/18

silicontrip commented 10 years ago

Hope this last Makefile change fixes these issues.

Nikoli commented 10 years ago

Works mostly fine now, but what about yuvilace.c? It does not link to fftw:

$ objdump -p yuvilace|grep NEEDED
  NEEDED               libmjpegutils-2.0.so.0
  NEEDED               libc.so.6

May be it is not used at all?

$ cat /tmp/cppcheck_lavtools.log|grep yuvilace
[yuvilace.c:91]: (style) The scope of the variable 't' can be reduced.
[yuvilace.c:349]: (style) The scope of the variable 'drop_frames' can be reduced.
[yuvilace.c:193]: (style) Unused variable: frame_data_size
[yuvilace.c:197]: (style) Variable 'l' is assigned a value that is never used.
[yuvilace.c:197]: (style) Variable 'f' is assigned a value that is never used.
[yuvilace.c:199]: (style) Variable 'points' is assigned a value that is never used.
[yuvilace.c:199]: (style) Variable 'window' is assigned a value that is never used.
[yuvilace.c:369]: (style) Variable 'drop_frames' is assigned a value that is never used.
[yuvilace.c:366]: (style) Variable 'src_interlacing' is assigned a value that is never used.
[yuvilace.c:396]: (style) Variable 'src_frame_rate' is assigned a value that is never used.
silicontrip commented 10 years ago

yuvilace was an experiment to detect interlacing using an fft. It was unable to fulfil it's original design, so is left in a half built state. I may've tried other methods of detecting interlacing, implemented in this code.