19

I'm doing cross compiling with CMake and all is OK but the CMAKE_AR options.

I use set(CMAKE_AR ${GCC_PATH}/dld) to set CMAKE_AR. But I don't know how to set its option. By default, it uses the options rc to create the archive. But I need to change it to be -X -r5 -o. When use rc, it will complain the file rc cannot be found.

How do I fix it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yantao Xie
  • 12,300
  • 15
  • 49
  • 79

1 Answers1

19

It looks like the flags "crs" are hardcoded in the command for creating an archive. There's no way to override just the flags; you have to rewrite the whole command, like this:

SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -X -r5 -o <TARGET> <LINK_FLAGS> <OBJECTS>")
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> -X -r5 -o <TARGET> <LINK_FLAGS> <OBJECTS>")

There's also a CMAKE_C_ARCHIVE_APPEND (and CXX equivalent) used when the number of objects exceeds the command line maximum, it passes just the "r" flag to CMAKE_AR. You may have to change that one too, see https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_ARCHIVE_CREATE.html

MarcH
  • 18,738
  • 1
  • 30
  • 25
richq
  • 55,548
  • 20
  • 150
  • 144
  • Thanks. It wrks. And I found those commands must be placed after the project(xxx) command. – Yantao Xie Apr 17 '11 at 07:38
  • If I has a so to append to target archive, what option(???>) should I append after ? Where is the reference of , and ? – naive231 Jan 09 '14 at 02:31