MantisBT - CMake
View Issue Details
0009556CMakeCMakepublic2009-09-17 11:002016-06-10 14:31
Keith Gardner 
Bill Hoffman 
normalminoralways
closedmoved 
CMake-2-6 
 
0009556: Linker Flags are not being pass for static libs in Visual Studio
When specifying specific linker flags for a static library target, the flags are being ignored. If I change the project to a shared library or an executable, the flags are passed like normal.
No tags attached.
Issue History
2009-09-17 11:00Keith GardnerNew Issue
2009-09-17 11:44Bill HoffmanNote Added: 0017589
2009-09-17 11:52Keith GardnerNote Added: 0017590
2009-09-17 12:10Bill HoffmanNote Added: 0017591
2009-09-17 12:10Bill HoffmanStatusnew => assigned
2009-09-17 12:10Bill HoffmanAssigned To => Bill Hoffman
2009-09-17 12:13Keith GardnerNote Added: 0017593
2011-01-11 15:36MaddesNote Added: 0024596
2011-01-11 15:37MaddesNote Edited: 0024596bug_revision_view_page.php?bugnote_id=24596#r107
2011-01-11 15:38MaddesNote Edited: 0024596bug_revision_view_page.php?bugnote_id=24596#r108
2011-01-15 13:15MaddesNote Edited: 0024596bug_revision_view_page.php?bugnote_id=24596#r120
2011-01-15 14:02MaddesNote Added: 0024720
2011-01-15 14:02MaddesNote Edited: 0024720bug_revision_view_page.php?bugnote_id=24720#r122
2011-01-15 14:03MaddesNote Edited: 0024720bug_revision_view_page.php?bugnote_id=24720#r123
2011-01-15 14:04MaddesNote Edited: 0024720bug_revision_view_page.php?bugnote_id=24720#r124
2011-01-15 18:01MaddesNote Added: 0024721
2011-01-15 18:03MaddesNote Deleted: 0024721
2011-01-15 18:11MaddesNote Added: 0024722
2011-01-28 16:51James BiglerNote Added: 0025158
2011-02-15 06:35Johan BjörkNote Added: 0025429
2016-06-10 14:27Kitware RobotNote Added: 0041594
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0017589)
Bill Hoffman   
2009-09-17 11:44   
That is because static libraries are not "linked"... What are you trying to do?
(0017590)
Keith Gardner   
2009-09-17 11:52   
I received an error on a project that stated that it could not identify the machine type and was defaulting to x86. This was all well and good until I needed to build the project as x64. I was able to specify the /MACHINE:x64 inside the solution but it was removed every time I reran CMake. I need to specify this flag so that our automated build server can compile the project.
(0017591)
Bill Hoffman   
2009-09-17 12:10   
Strange, we can build CMake 64 bit and it has a static library.
(0017593)
Keith Gardner   
2009-09-17 12:13   
I have probably 20 different libraries that we make at work and only one has this issue. They all have the same configuration and have the same macros run against them but this one library has this issue. All I am saying is even though it doesn't make sense to have linker flags, having that functionality available would be good for fixing unexpected problems like this.
(0024596)
Maddes   
2011-01-11 15:36   
(edited on: 2011-01-15 13:15)
This issue is very important to me.

The static library I build calls functions from a Hardware Driver DLL.
I want to link it with the DLL import lib of the Hardware Driver DLL.
This way users of my static library do not need the DLL import lib for building their projects.

I expected that values of link_directories() and target_link_libraries() would be added to the "Librarian -> General" section of VS2005/2008 configurations.
Unfortunately this is not the case and I have to manually edit the project files.
These link libraries should not be added to other targets, which link with this static library (as they are already inside the static lib).

Also tried a workaround with STATIC_LIBRARY_FLAGS but that failed too :(
set(STATIC_LIBRARY_FLAGS ${STATIC_LIBRARY_FLAGS} /LIBPATH:"C:\usr\local\lib" ${libraries})

(0024720)
Maddes   
2011-01-15 14:02   
(edited on: 2011-01-15 14:04)
After reading lots of articles on MSDN and elsewhere: You are right that's not a linker step, but a library step.
IMHO "link_directories()", "target_link_libraries()" and target property LINK_FLAGS should also apply to a library step, as it just places these libs inside the output library in some way.
Or provide "lib_directories()" and "target_lib_libraries()" for static library builds, maybe provide a target property LIB_FLAGS too.

MSDN infos about LIB command and project file extracts:
* VC6:
http://msdn.microsoft.com/en-us/library/aa270431%28v=VS.60%29.aspx [^] , see "Running LIB" and "Managing a Library"

!IF "$(CFG)" == "pinproc - Win32 Release"
...
# ADD BASE LIB32 /nologo
# ADD LIB32 ftd2xx.lib /LIBPATH:"\usr\local\lib\Release" /LIBPATH:"\usr\local\lib" /nologo /out:".\Release/libpinprocmt.lib"
...

* VS2002+:
  http://msdn.microsoft.com/en-us/library/7ykb2k5f.aspx [^] , see "Running LIB" and "Managing a Library"

<VisualStudioProject>
    <Configurations>
        <Configuration>
            <Tool
                Name="VCLibrarianTool"
                AdditionalDependencies="ftd2xx.lib"
                AdditionalLibraryDirectories="\usr\local\lib\$(OutDir),\usr\local\lib"
                OutputFile="$(OutDir)\libpinprocmtd.lib"
            />
        </Configuration>

(0024722)
Maddes   
2011-01-15 18:11   
The same is not possible with GCC (here MinGW).
I tried to add the "target_link_libraries()" to the AR.EXE command, but they will not be recognized when the resulting static library is used in another project.

Seems the functionality mentioned above in note 0024720 would only be MSVC only.
Still it would be a great feature for MSVC users.
(0025158)
James Bigler   
2011-01-28 16:51   
I also just ran into this issue. I want to compile my code with /GL (link time code generation), but when the static library is created I get the following error:

Creating command line "lib.exe @"c:\code\build-32-vs9-c32\src\stitch.dir\Release\RSP0006AF15525948.rsp" /NOLOGO"

MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance

That's fine. I can add that flag in the GUI in the "Command Line" section of the "Librarian" and this phase of the compile completes without warnings. However, I'm stumped to figure out how to get this flag added by default by CMake.
(0025429)
Johan Björk   
2011-02-15 06:35   
James,

You can set STATIC_LIBRARY_FLAGS for each add_library() target to work around this. I just asked on the e-mail list for a global property.

 (If you have many targets, you can override the add_library() function)
(0041594)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.