[CMake] Windows library target names

Michael Jackson mike.jackson at bluequartz.net
Thu Jul 22 17:36:16 EDT 2010


On Jul 22, 2010, at 5:25 PM, Olaf van der Spek wrote:

> On Thu, Jul 22, 2010 at 11:14 PM, Michael Jackson
> <mike.jackson at bluequartz.net> wrote:
>>    So here is what really happens with Visual Studio. When you  
>> invoke CMake
>> you select to build "Shared" libraries and a Win64 application.  
>> These are
>> the basics. Visual Studio will create a subdirectory for "Debug" and
>> "Release" variants for you. So when you build you get a shared  
>> library with
>> debug symbols placed in the Build/Debug/ directory and the same for  
>> Release
>> (Build/Release). Now. since these are completely separate  
>> directories when
>> you execute your program the correct libraries will be found.  
>> Great. This
>
> How does the loader find the DLL?

Because when Visual Studio launches an executable it will look in the  
same directory that the executable resides in for libraries to load.  
Now, if you have 2 completely separate projects where one builds  
libraries and the other builds the executables OR you have set the  
various CMAKE_RUNTIME_DIR, CMAKE_ARCHIVE_DIR and CMAKE_EXECUTABLE_DIR  
to different directories then you are going to have to setup your PATH  
accordingly for each solution/project. Most people set all three of  
those CMake variables to the same output directory.

>
>> falls apart if you "install" your project to a location for other  
>> projects
>> to get to. Then one library will over write the other.
>>
>>   In a typical CMake workflow one would create another build  
>> directory and
>> rerun CMake again to generate another Visual Studio solution that  
>> would have
>> say a 32 bit Static build in it. This is what CMake kind of  
>> expects. You can
>> abuse this if you want. Take a look at the boost-cmake project.
>
> Why is this abuse?

Because it circumvents CMakes generally accepted practice of a single  
type of configuration per build directory. I guess "abuse" is subject  
to each different person.

>
>>   If you want to go even further and decorate your library names  
>> like boost
>> does then go ahead and write the CMake code (or grab it from the  
>> Boost-cmake
>> project). CMake only needs to do what the other platforms do which  
>> is NOT
>> decorate the library names. VS does not do this by default.
>
> If I look in C:\Program Files (x86)\Microsoft Visual Studio
> 10.0\VC\lib I see plenty of libs with a "d" suffix...

Sorry, I got the idea of decorating the debug versions confused with  
naming of static and dynamic libraries. My Bad. You are correct. But  
that is one platform and CMake generally has to play down to the  
lowest common denominator. On OS X the decoration seems to be _debug.  
Not sure what it is on Linux, solaris, AIX or some of the other  
Operating Systems that CMake supports.

>
>>   You _can_ very easily do this if you want. The code is out there  
>> in the
>> wild in the form of macros that can be invoked from CMake that will  
>> set all
>> of this up for you. You just have to look for it (or ask the right  
>> person...
>> )
>>
>> Does that help?
>
> Not sure.
>
> Olaf

Mike


More information about the CMake mailing list