[cmake-developers] [CMake 0015495]: cmake prevents linking static runtime with absolute path to a static lib

Mantis Bug Tracker mantis at public.kitware.com
Sat Apr 4 01:31:57 EDT 2015


The following issue has been SUBMITTED. 
====================================================================== 
http://public.kitware.com/Bug/view.php?id=15495 
====================================================================== 
Reported By:                Norbert Pfeiler
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15495
Category:                   CMake
Reproducibility:            always
Severity:                   minor
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2015-04-04 01:31 EDT
Last Modified:              2015-04-04 01:31 EDT
====================================================================== 
Summary:                    cmake prevents linking static runtime with absolute
path to a static lib
Description: 
When an absolute path to a static lib i.e. ${ZLIB_LIBRARIES}, which expands to
D:/msys64/mingw64/lib/libz.a is added to target_link_libraries, the library is
linked using its name (-lz), preprended with -Wl,-Bstatic and appended with
-Wl,-Bdynamic. Because the libraries appear after any link flags, the latter one
cancels out any flags to link statically (-static -static-libstdc++
-static-libgcc) and the final executable links against the dynamic runtime. 
Using an imported target i.e. ZLIB::ZLIB, the library is added using its
absolute path without any additional flags. 

Steps to Reproduce: 
add static link flags
add static lib via its absolute path
the final executable links against the dynamic runtime

Additional Information: 
[1/4] D:\msys64\mingw64\bin\c++.exe     -MMD -MT
CMakeFiles/static_lib_test1.dir/main.cpp.obj -MF
CMakeFiles/static_lib_test1.dir/main.cpp.obj.d -o
CMakeFiles/static_lib_test1.dir/main.cpp.obj -c ../main.cpp
[2/4] D:\msys64\mingw64\bin\c++.exe    -isystem D:/msys64/mingw64/include -MMD
-MT CMakeFiles/static_lib_test2.dir/main.cpp.obj -MF
CMakeFiles/static_lib_test2.dir/main.cpp.obj.d -o
CMakeFiles/static_lib_test2.dir/main.cpp.obj -c ../main.cpp
[3/4] cmd.exe /C "cd . && D:\msys64\mingw64\bin\c++.exe    
CMakeFiles/static_lib_test1.dir/main.cpp.obj  -o static_lib_test1.exe
-Wl,--out-implib,libstatic_lib_test1.dll.a
-Wl,--major-image-version,0,--minor-image-version,0  -static -static-libstdc++
-static-libgcc -Wl,-Bstatic -lz -Wl,-Bdynamic -lkernel32 -luser32 -lgdi32
-lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
[4/4] cmd.exe /C "cd . && D:\msys64\mingw64\bin\c++.exe    
CMakeFiles/static_lib_test2.dir/main.cpp.obj  -o static_lib_test2.exe
-Wl,--out-implib,libstatic_lib_test2.dll.a
-Wl,--major-image-version,0,--minor-image-version,0  -static -static-libstdc++
-static-libgcc D:/msys64/mingw64/lib/libz.a -lkernel32 -luser32 -lgdi32
-lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
static_lib_test1.exe:
	ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x777d0000)
	kernel32.dll => /c/Windows/system32/kernel32.dll (0x776b0000)
	KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7fefd7b0000)
	msvcrt.dll => /c/Windows/system32/msvcrt.dll (0x7fefde30000)
	libstdc++-6.dll => /mingw64/bin/libstdc++-6.dll (0x6fc40000)
	libgcc_s_seh-1.dll => /mingw64/bin/libgcc_s_seh-1.dll (0x61440000)
	libwinpthread-1.dll => /mingw64/bin/libwinpthread-1.dll (0x64940000)
	USER32.dll => /c/Windows/system32/USER32.dll (0x775b0000)
	GDI32.dll => /c/Windows/system32/GDI32.dll (0x7fefe110000)
	LPK.dll => /c/Windows/system32/LPK.dll (0x7feffad0000)
	USP10.dll => /c/Windows/system32/USP10.dll (0x7fefd950000)
	IMM32.DLL => /c/Windows/system32/IMM32.DLL (0x7fefde00000)
	MSCTF.dll => /c/Windows/system32/MSCTF.dll (0x7fefdca0000)
static_lib_test2.exe:
	ntdll.dll => /c/Windows/SYSTEM32/ntdll.dll (0x777d0000)
	kernel32.dll => /c/Windows/system32/kernel32.dll (0x776b0000)
	KERNELBASE.dll => /c/Windows/system32/KERNELBASE.dll (0x7fefd7b0000)
	msvcrt.dll => /c/Windows/system32/msvcrt.dll (0x7fefde30000)

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2015-04-04 01:31 Norbert PfeilerNew Issue                                    
2015-04-04 01:31 Norbert PfeilerFile Added: cmake static lib test.7z            
       
======================================================================



More information about the cmake-developers mailing list