[cmake-developers] [CMake 0014463]: Linking fails with a gcc build with compound circular library dependencies.

Mantis Bug Tracker mantis at public.kitware.com
Tue Oct 8 12:15:54 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=14463 
====================================================================== 
Reported By:                John Szwast
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14463
Category:                   (No Category)
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2013-10-08 12:15 EDT
Last Modified:              2013-10-08 12:15 EDT
====================================================================== 
Summary:                    Linking fails with a gcc build with compound
circular library dependencies.
Description: 
On a project with a library dependency cycle and a strict path of dependency,
linking with gcc fails.

Steps to Reproduce: 
Attempt to build the attached example project with gcc.
The linker error will be of the form:

c\libc.a(c.obj):c.c:(.text+0xd): undefined reference to `do_b'
collect2.exe: error: ld returned 1 exit status
CMakeFiles\demo.dir\build.make:97: recipe for target 'demo.exe' failed
mingw32-make[2]: *** [demo.exe] Error 1
CMakeFiles\Makefile2:62: recipe for target 'CMakeFiles/demo.dir/all' failed
mingw32-make[1]: *** [CMakeFiles/demo.dir/all] Error 2
Makefile:74: recipe for target 'all' failed
mingw32-make: *** [all] Error 2


Additional Information: 
I've encountered this with each of the following setups:
Windows 7 64-bit with CMake 2.8.11.2 using "MinGW Makefiles" generator.
Windows 7 64-bit with CMake 2.8.11.2 using "Ninja" generator.
Linux Mint 64-bit with CMake 2.8.9 using the default (Unix Makefiles) generator.

Each CMakeLists.txt file in the example project accurately specifies the
libraries' dependencies with target_link_libraries() statements.

         c --> b
         ^     |
         |     v
demo --> d --> a
         ^     |
         |     |
         +-----+

The generated link command lists each pair of dependent libraries in the
required order, but the whole dependency path of d -> c -> b -> a is not
realized in the linker's library list order:

c:\MinGW\bin\gcc.exe      -Wl,--whole-archive CMakeFiles\demo.dir/objects.a
-Wl,--no-whole-archive  -o demo.exe -Wl,--out-implib,libdemo.dll.a
-Wl,--major-image-version,0,--minor-image-version,0  a\liba.a b\libb.a c\libc.a
d\libd.a a\liba.a b\libb.a c\libc.a d\libd.a -lkernel32 -luser32 -lgdi32
-lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 

So the parts of library a that are only used by b and not d are not available. 
And the part of b that does use library a isn't even getting linked in because
the part of library c that uses it wasn't linked in yet when b's turn came
around.
====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-10-08 12:15 John Szwast    New Issue                                    
2013-10-08 12:15 John Szwast    File Added: CMake MinGW MWE.zip                 
  
======================================================================




More information about the cmake-developers mailing list