Bug #2448

LINK_FLAGS placed before object files during linking

Added by gureedo almost 2 years ago. Updated about 1 year ago.

Status:FixedStart date:2012-09-26
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:build_cmake
Target version:1.4.33
Missing in 1.5.x:No

Description

LINK_FLAGS variable holds additional options for linking, such as some LDFLAGS and LIBS.
During linking cmake places this variable before object files and we got something like this:

/usr/bin/gcc -std=gnu99 -Wall -g -Wshadow -W -pedantic -L/usr/lib/x86_64-linux-gnu -lpcre
-export-dynamic CMakeFiles/lighttpd.dir/server.o CMakeFiles/lighttpd.dir/response.o
CMakeFiles/lighttpd.dir/connections.o CMakeFiles/lighttpd.dir/network.o 
CMakeFiles/lighttpd.dir/configfile.o CMakeFiles/lighttpd.dir/configparser.o 
CMakeFiles/lighttpd.dir/request.o CMakeFiles/lighttpd.dir/proc_open.o 
CMakeFiles/lighttpd.dir/buffer.o CMakeFiles/lighttpd.dir/log.o 
CMakeFiles/lighttpd.dir/keyvalue.o CMakeFiles/lighttpd.dir/chunk.o 
CMakeFiles/lighttpd.dir/http_chunk.o CMakeFiles/lighttpd.dir/stream.o 
CMakeFiles/lighttpd.dir/fdevent.o CMakeFiles/lighttpd.dir/stat_cache.o 
CMakeFiles/lighttpd.dir/plugin.o CMakeFiles/lighttpd.dir/joblist.o 
CMakeFiles/lighttpd.dir/etag.o CMakeFiles/lighttpd.dir/array.o 
CMakeFiles/lighttpd.dir/data_string.o CMakeFiles/lighttpd.dir/data_count.o 
CMakeFiles/lighttpd.dir/data_array.o CMakeFiles/lighttpd.dir/data_integer.o 
CMakeFiles/lighttpd.dir/md5.o CMakeFiles/lighttpd.dir/data_fastcgi.o 
CMakeFiles/lighttpd.dir/fdevent_select.o CMakeFiles/lighttpd.dir/fdevent_libev.o 
CMakeFiles/lighttpd.dir/fdevent_poll.o CMakeFiles/lighttpd.dir/fdevent_linux_sysepoll.o 
CMakeFiles/lighttpd.dir/fdevent_solaris_devpoll.o 
CMakeFiles/lighttpd.dir/fdevent_solaris_port.o 
CMakeFiles/lighttpd.dir/fdevent_freebsd_kqueue.o CMakeFiles/lighttpd.dir/data_config.o 
CMakeFiles/lighttpd.dir/bitset.o CMakeFiles/lighttpd.dir/inet_ntop_cache.o 
CMakeFiles/lighttpd.dir/crc32.o CMakeFiles/lighttpd.dir/connections-glue.o 
CMakeFiles/lighttpd.dir/configfile-glue.o CMakeFiles/lighttpd.dir/http-header-glue.o 
CMakeFiles/lighttpd.dir/splaytree.o CMakeFiles/lighttpd.dir/network_writev.o 
CMakeFiles/lighttpd.dir/network_write.o CMakeFiles/lighttpd.dir/network_linux_sendfile.o 
CMakeFiles/lighttpd.dir/network_freebsd_sendfile.o 
CMakeFiles/lighttpd.dir/network_solaris_sendfilev.o CMakeFiles/lighttpd.dir/network_openssl.o 
CMakeFiles/lighttpd.dir/status_counter.o  -o lighttpd -rdynamic -ldl

gcc manual says about -l flag: It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but before bar.o. If bar.o refers to functions in `z', those functions may not be loaded.

if i manually move LINK_FLAGS to end of command then linking completes succesfully.

software:
cmake v2.8.7
gcc v4.6.3
make v3.81

Associated revisions

Revision 2875
Added by stbuehler about 1 year ago

[cmake] Use TARGET_LINK_LIBRARIES instead of LINK_FLAGS for library dependencies, also add -Wl,--as-needed to extra warnings (fixes #2448)

History

#1 Updated by stbuehler about 1 year ago

  • Target version changed from 1.4.x to 1.4.33

#2 Updated by stbuehler about 1 year ago

  • Status changed from New to Fixed
  • % Done changed from 0 to 100

Applied in changeset r2875.

Also available in: Atom