[CMake] Fortran program linked with C++ library
Marcin Wojdyr
wojdyr at gmail.com
Wed Sep 4 11:14:54 EDT 2013
Thanks, it works.
Since the library is found in Find* script, I have to check if it is static.
So I ended up with this:
if("${MMDB_LIBRARY}" MATCHES "\\.a$")
# it cannot be just "UNKNOWN IMPORTED", because
# IMPORTED_LINK_INTERFACE_LANGUAGES is respected only for "STATIC IMPORTED"
add_library(mmdb_cxxlib STATIC IMPORTED)
else()
add_library(mmdb_cxxlib UNKNOWN IMPORTED)
endif()
set_target_properties(mmdb_cxxlib PROPERTIES
IMPORTED_LOCATION ${MMDB_LIBRARY}
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX")
...
foreach(p ...)
set_property(TARGET ${p} PROPERTY LINKER_LANGUAGE Fortran)
endforeach(p)
Two feature requests come to my mind:
- IMHO it would be better if the language of external library didn't
change linker language,
- and a function that tells if the library is static would also be nice
Cheers
Marcin
On 3 September 2013 19:08, Brad King <brad.king at kitware.com> wrote:
> On 09/03/2013 01:57 PM, Marcin Wojdyr wrote:
>> On 3 September 2013 15:46, Brad King <brad.king at kitware.com> wrote:
>>> One way to do this is to tell CMake that the library uses C++
>>> using the IMPORTED_LINK_INTERFACE_LANGUAGES property on an
>>
>> That's what I was looking for, but for me instead of adding C++
>> runtime, C++ compiler (icpc) is used for linking.
>> So I have the same problem:
>> undefined reference to `main'
>
> Now set LINKER_LANGUAGE to "Fortran" to tell it that your main
> is there. I think the LINKER_PREFERENCE infrastructure may be
> outdated.
>
> -Brad
More information about the CMake
mailing list