complex situation: Re: [Cmake] how to find STATIC library, ignore DYNAMIC library

William A. Hoffman billlist at nycap.rr.com
Thu Aug 19 14:06:34 EDT 2004


You could try something like this.

1. Find the HDF static library with FIND_LIBRARY
2. Copy the static library into a directory in your build tree
with 

EXEC_PROGRAM( ${CMAKE_COMMAND} -E copy_if_different ${HDF_LIB} ${PROJECT_BINARY_DIR}/HDFStaticLib)

3. Add the link directory for HDFStaticLib first with
LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/HDFStaticLib)

4. Add the library like this:
TARGET_LINK_LIBRARIES(foo ${PROJECT_BINARY_DIR}/HDFStaticLib/HDF)

-Bill



At 01:23 PM 8/19/2004, Liwei Peng wrote:
>Hi Brand,
>
>thanks for your quick response. 
>
>My situation is a little bit complex. 
>1) My program needs to link about 5 libraries
>including HDF. while I want to have HDF statically
>linked, for the other 4 libraries, I want them to be
>dynamically linked.
>
>2) The program is being ported to multiple platforms
>including linux, sgi, ibm aix, sun solaris, even
>windows. so a platform-specific flag may not be easy
>to do by myself. if CMake provides this flag, that'll
>be great.
>
>Thanks,
>
>Liwei
>
>
>--- Brad King <brad.king at kitware.com> wrote:
>
>> Liwei Peng wrote:
>> > I am a CMake user for a long time. Recently I have
>> a
>> > problem in using CMake to find the right library.
>> 
>> This has been a common problem due to unix linker
>> limitations.  I have 
>> some ideas on how to fix it which I've documented in
>> this feature request:
>> 
>> http://www.cmake.org/Bug/bug.php?op=show&bugid=1105
>> 
>> > In my program, I need to link HDF library. In my
>> > computer, there are both HDF dynamic
>> > library(libhdf5.so) and HDF static
>> library(libhdf5.a)
>> > installed under /usr/lib. I want to link the
>> static
>> > library. but CMake always go to the dynamic
>> library.
>> > Is there any way in CMake that I can force it to
>> use
>> > static instead of dynamic?
>> 
>> This can be fixed on a per-platform basis by
>> including the proper linker 
>> flag in your CMAKE_EXE_LINKER_FLAGS variable.  I
>> think adding something 
>> like -Bstatic will tell the linker to use only
>> static libraries.  You 
>> will have to read the documentation for your linker
>> to find the proper flag.
>> 
>> -Brad
>> 
>
>
>__________________________________________________
>Do You Yahoo!?
>Tired of spam?  Yahoo! Mail has the best spam protection around 
>http://mail.yahoo.com 
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake 



More information about the Cmake mailing list