Ticket #1136 (closed defect: fixed)
Multiple _LIBS variables are confused with _LDFLAGS
| Reported by: | RedDwarf69 | Owned by: | verm |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.1.9 |
| Component: | General | Version: | 2.1.8 |
| Severity: | minor | Keywords: | |
| Cc: | Platform: | All | |
| Sub Component: |
Description
Multiple _LIBS variables are confused with _LDFLAGS. Try to compile with --as-needed to see the long list of problems it causes.
The attached patch fixes most of them.
Attachments
Change History
Changed 2 years ago by RedDwarf69
-
attachment
aegisub-2.1.8-as_needed.patch
added
comment:1 Changed 23 months ago by ranma
Just a 'me too'. I ran into this issue while trying to compile aegisub on Debian/testing with ffmpeg and ffmpegsource both compiled from svn and installed into /usr/local. It didn't detect FFMPEG because due to using LDFLAGS instead of LIBS the g++ commandline ended up with the cpp source specified _after_ the libs instead of _before_ the libs and so it bailed out with 'undefined reference' errors.
For an explanation of the underlying issue see:
http://www.network-theory.co.uk/docs/gccintro/gccintro_18.html
Which states "Most current linkers will search all libraries, regardless of order, but since some do not do this it is best to follow the convention of ordering libraries from left to right.", so apparently the gnu linker is not 'most current linkers' because it still needs the left to right ordering for libraries at least on my system.
ranma@navi:~$ g++ --version
g++ (Debian 4.3.4-6) 4.3.4
ranma@navi:~$ ld --version
GNU ld (GNU Binutils for Debian) 2.20
comment:2 Changed 23 months ago by ranma
ranma@navi:/tmp$ g++ -o conftest -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-long-long -fpermissive -fno-strict-aliasing -std=c++98 -pipe -O2 -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -L/usr/local/lib -lswscale -lavutil -L/usr/local/lib -lavcodec -lz -lm -ldl -lasound -lavutil -L/usr/local/lib -lavformat -lavcodec -lz -lm -ldl -lasound -lavutil -L/usr/local/lib -lavutil conftest.cpp -lm
conftest.cpp: In function ‘int main()’:
conftest.cpp:13: warning: ‘AVFormatContext* av_alloc_format_context()’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:916)
conftest.cpp:13: warning: ‘AVFormatContext* av_alloc_format_context()’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:916)
/tmp/ccM5Kzlw.o: In function `main':
/tmp/conftest.cpp:12: undefined reference to `av_register_all'
/tmp/conftest.cpp:13: undefined reference to `av_alloc_format_context'
/tmp/conftest.cpp:18: undefined reference to `av_free'
/tmp/conftest.cpp:20: undefined reference to `avcodec_init'
/tmp/conftest.cpp:21: undefined reference to `avcodec_register_all'
/tmp/conftest.cpp:22: undefined reference to `avcodec_find_decoder'
/tmp/conftest.cpp:28: undefined reference to `sws_getContext'
/tmp/conftest.cpp:33: undefined reference to `sws_freeContext'
collect2: ld returned 1 exit status
ranma@navi:/tmp$ g++ -o conftest -g -O2 -Wall -Wextra -Wno-unused-parameter -Wno-long-long -fpermissive -fno-strict-aliasing -std=c++98 -pipe -O2 -I/usr/local/include -I/usr/local/include -I/usr/local/include -I/usr/local/include -L/usr/local/lib conftest.cpp -lswscale -lavutil -L/usr/local/lib -lavcodec -lz -lm -ldl -lasound -lavutil -L/usr/local/lib -lavformat -lavcodec -lz -lm -ldl -lasound -lavutil -L/usr/local/lib -lavutil -lm
conftest.cpp: In function ‘int main()’:
conftest.cpp:13: warning: ‘AVFormatContext* av_alloc_format_context()’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:916)
conftest.cpp:13: warning: ‘AVFormatContext* av_alloc_format_context()’ is deprecated (declared at /usr/local/include/libavformat/avformat.h:916)
ranma@navi:/tmp$
comment:4 Changed 15 months ago by RedDwarf69
Sorry? Sure, ffmpeg libraries are shared libraries.
But the thing is ( http://sourceware.org/binutils/docs-2.20/ld/Options.html#Options):
"The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again."
And autoconf/automake docs say _LDFLAGS should not be used to add libraries. _LDADD, _LIBADD and _LIBS should be used for that. See http://www.gnu.org/software/autoconf/manual/autoconf.html#Preset-Output-Variables:
"— Variable: LDFLAGS
Options for the linker. If it is not set in the environment when configure runs, the default value is empty. configure uses this variable when linking programs to test for C, C++, Objective C, Objective C++, and Fortran features.
This variable's contents should contain options like -s and -L that affect only the behavior of the linker. Please see the explanation of CFLAGS for what you can do if an option also affects other phases of the compiler.
Don't use this variable to pass library names (-l) to the linker; use LIBS instead.
— Variable: LIBS
-l options to pass to the linker. The default value is empty, but some Autoconf macros may prepend extra libraries to this variable if those libraries are found and provide necessary functions, see Libraries. configure uses this variable when linking programs to test for C, C++, Objective C, Objective C++, and Fortran features. )"
comment:5 Changed 14 months ago by verm
- Owner set to verm
- Status changed from new to assigned
- Milestone set to 2.1.9
Make sure this is taken care of for 2.1.9..
comment:6 Changed 12 months ago by verm
- Status changed from assigned to closed
- Resolution set to wontfix
- Milestone 2.1.9 deleted
automake is gone in trunk, I'm not going to bother fixing this for 2.1.9 as this will be the last version in 2.1 with the exception of 2.1.10 which will be bugfixes only.
comment:7 Changed 12 months ago by TheFluff
- Status changed from closed to reopened
- Resolution wontfix deleted
Being able to compile the program is sort of important. Reopened.

Patch