[CMake] how to mix C and C++ modules and link them in a particular way ?

Vania Joloboff vania.joloboff at inria.fr
Thu Feb 11 03:44:43 EST 2016


Hi

I have say mod1.cc and mod2.cc that are C++ files
plus mod3.c and mod4.c that are C files
and I need to link them with a specific linker and link
command.
I want to compile them and after that link them
with specific linker command.
I do not want to use the toolchain linker.

I thought the following would work

add_library(Cxxcode OBJECT mod1.cc mod2.cc)
add_library(Ccode OBJECT mod3.c mod4.c)
add_custom_target(prog
  COMMAND "${MY_LINKER} $<TARGET_OBJECTS:Ccode> <TARGET_OBJECTS:Cxxcode> 
  ${MY_LINK_OPTIONS} -o prog"
  COMMENT "Linking mix C++ and C"
  )

But I get error
The evaluation of the TARGET_OBJECTS generator expression is only 
suitable for consumption by CMake.

So how can I do this ?




More information about the CMake mailing list