[CMake] Fwd: MSVC7.1 static link question

ankit jain ankitguddu at gmail.com
Wed Feb 11 00:15:42 EST 2009


---------- Forwarded message ----------
From: ankit jain <ankitguddu at gmail.com>
Date: 2009/2/11
Subject: Re: [CMake] MSVC7.1 static link question
To: Brad King <brad.king at kitware.com>




2009/2/10 Brad King <brad.king at kitware.com>

  Luigi Calori wrote:
>
>> Bill Hoffman ha scritto:
>>
>>> Philip Lowman wrote:
>>>
>>>> On Mon, Feb 9, 2009 at 12:39 PM, Luigi Calori <l.calori at cineca.it<mailto:
>>>> l.calori at cineca.it>> wrote:
>>>>
>>>>    I' m quite a newbie in static linking, I would like to combine two
>>>> lib
>>>>    into one:
>>>>    say libtiff needs libjpeg and zlib
>>>>    If you generate them separately, then when you build an executable
>>>> that
>>>>    needs libtiff, you have to link also libjpeg and zlib otherwise unref
>>>>    happens
>>>>    It is possible, under VisualStudio interface, to specify libjpeg.lib
>>>> and
>>>>    zlib.lib as Additional Dependencies
>>>>    This way (even if the linker show warnings as duplicate symbols) I
>>>>    obtain a libtiff that can be used alone.
>>>>    My question is: can I obtain the same result with cmake?
>>>>    I' ve tried to use TARGET_LINK_LIBRARIES, that is perfecly working
>>>> for
>>>>    exe and SHARED linkage but no success: the
>>>>    vs project has always the Additional Dependencies field empty.
>>>>
>>>>    Am I completely missing something?
>>>>
>>>> CMake does not work that way since it is not achievable cross platform.
>>>  If you project is CMake based CMake will chain the libraries.  If you use
>>> other build tools then you will have to explicitly list libjpeg and zlib
>>> with the libtiff.  To do this in CMake you have two options:
>>>
>>> 1. have a library that uses libtiff
>>> add_library(mylib ...)
>>> target_link_libraries(mylib libtiff libjepg zlib)
>>> add_executable(myexe ...)
>>> target_link_libraries(myexe mylib)  # will link in tiff jpeg and zlib
>>>
>>> 2. create an imported target for libtiff
>>> add_library(libtiff IMPORTED)
>>> set_target_properties(libtiff PROPERTIES IMPORTED_LOCATION
>>> /path/to/libtiff.lib)
>>> target_link_libraries(libtiff libjpeg zlib)
>>> add_executable(myexe ...)
>>> target_link_libraries(myexe libtiff) # will link jpeg and zlib
>>>
>>>
>>> -Bill
>>>
>>>
>>>
>>> Hi Philip and Bill:
>>
>> I tried Philip suggestion and it seem working: it adds the flags as
>> Additiona Optins in the commandline form and it seems to produce a
>> libtiff.lib that links ok.
>> The problem is that STATIC_LIBRARY_FLAGS property is not differentiated
>> between Debug / Release.
>>
>> Bill, is your method equivalent?
>>
>> Is your suggestion applicable if the  exe and the lib stay in two
>> completely different projects?
>>
>> What I mean is that I ' m willing to have a CMake project that BUILDS and
>> install libtiff.lib (static)
>>
>> Then I have another project that build a .dll (or .exe, I think it behave
>> the same) that Find and use my libtiff.lib.
>>
>> Both your suggested method  seem to assume that myexe and libtiff are
>> built at the same time.
>> This is not my case, I would like build libtiff static on win32 in such a
>> way that allow other projects (built with cmake) to link it without adding
>> explicitly the other dependent libraries.
>> so to not require changes in the dependent project (it is actually
>> OpenSceneGraph, Philip)
>> So either modifying VS project or adding STATIC_LIBRARY_FLAGS I  am able
>> to do.
>>
>> I tried to use IMPORTED bud it did not worked
>>
>
> Bill's example will not work as written.  The target_link_libraries command
> does not work for imported targets.  See IMPORTED target and general
> packaging documentation here:
>
>  http://www.cmake.org/Wiki/CMake_2.6_Notes#Exporting_and_Importing_Targets
>  http://www.cmake.org/Wiki/CMake_2.6_Notes#Packages
>
> CMake 2.6 makes it easy to export targets from one project (either its
> build tree or install tree) for use by another project.
>
> -Brad
>


>  If our library which we want to link is not in the curre tn project and
> we linkan executable to it through target_link_libraries by giving it entire
> path like /another/project/lib, will it not work properly. is it compulsory
> to use import and export targets for it.
>

Ankit

>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090211/6808f0cf/attachment.htm>


More information about the CMake mailing list