[CMake] linkage order of static libraries and object files (ENABLE_EXPORTS)

Ivan Sergio Borgonovo mail at webthatworks.it
Sat Nov 2 02:50:26 EDT 2013


I'm trying to convert an embedded eclipse project to CMake with a
python script.

I reached a point where everything compile as I want, everything get
listed in the linking step but libraries are in the wrong order and
linking fail.

Just reordering the libraries list and running the linking process by
hand produce the right executable.

I want to convert the project in a completely automatic way and I don't
want my python code to get too complicated to understand
inter-libraries dependencies to write smarter CMakeLists.txt files or
to order properly the libraries unless there is a very simple way to do
so. This would be sweet but I don't think there is a simple way.

Eclipse was compiling everything as objects so order of linking was not
important.

I've tried to follow
http://www.cmake.org/Wiki/CMake/Tutorials/Object_Library
I get

CMake Error at cmakedirs.cmake:118 (target_link_libraries):
  Target "serial" of type OBJECT_LIBRARY may not be linked into another
  target.  One may link only to STATIC or SHARED libraries, or to
executables with the ENABLE_EXPORTS property set.
Call Stack (most recent call first):
  CMakeLists.txt:89 (include)

for all libraries

But I can't get rid of the same error even when I add:
add_executable(project main.c)
set_target_properties(project PROPERTIES ENABLE_EXPORTS ON) #<--


-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the CMake mailing list