0

I am trying to set up my CMakeLists.txt for a C++ project using a cross-compile toolchain (e.g. TI Code Composer Studio). I almost have it, but am stuck when it comes to adding a library to a link command. Boiling it down to basics, the tools want a command of this form:

armcl $(LINK_FLAGS) $(OBJS) $(LIBRARIES)

where the libraries are specified after all object files. If libraries are not after the object files, the linker doesn't recognize them.

However, I keep generating a command like:

armcl $(LINKER_OPTIONS) $(LIBRARIES) $(OBJS)

I use CMAKE_CXX_LINK_FLAGS to get the $(LINK_FLAGS), and use target_link_libraries() to specify the libraries.

set(CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS} --heap_size=18000")

target_link_libraries(mtrs PRIVATE -llibc.a driverlib.lib)

How can I force CMake to generate link commands with libraries at the end?

Bob
  • 587
  • 8
  • 17
  • It looks like something wrong with your toolchain. The correct one should never emit a command line in form `armcl $(LINKER_OPTIONS) $(LIBRARIES) $(OBJS)`. Search for [CMAKE_C_LINK_EXECUTABLE](https://cmake.org/cmake/help/v3.7/variable/CMAKE_LANG_LINK_EXECUTABLE.html) or [CMAKE_C_CREATE_SHARED_LIBRARY](https://cmake.org/cmake/help/v3.7/variable/CMAKE_LANG_CREATE_SHARED_LIBRARY.html) variable in your toolchain. – Tsyvarev Jun 26 '19 at 15:34
  • It is a C++ project, but your comment is still interesting. I have no CMAKE_CXX_LINK_EXECUTABLE in my toolchain file, but I don't know how to specify an appropriate value. – Bob Jun 26 '19 at 15:49
  • Ah, I did find a TI-CXX.cmake file in /usr/share/cmake-3.14/Modules/Compiler/ that does look like it is being used, and it indeed places the object files at the end. I grabbed the CMAKE_CXX_LINK_EXECUTABLE variable from there, put it in to my local toolchain file (e.g. "cmake -DCMAKE_TOOLCHAIN_FILE=my_toolchain.cmake") but no difference; the objects are still last. I thought that would override the file in /usr/share/cmake... – Bob Jun 26 '19 at 16:01
  • You may set the variable in the `CMakeLists.txt` after the `project()` call. – Tsyvarev Jun 26 '19 at 16:22
  • Editing the TI-CXX.cmake file works, but that seems wrong, as that is editing part of CMake itself. – Bob Jun 26 '19 at 19:14
  • Editing the TI-CXX.cmake file works, but that seems wrong, as that is editing part of CMake itself. Editing my toolchain file does NOT work. However, editing CMakeLists.txt (after project()) DOES indeed work. Not sure why it needs to be there, but my problem has been solved. THANKS!!! – Bob Jun 26 '19 at 19:23

0 Answers0