[CMake] Linker and archiver options

Irina Chernushina ichern at google.com
Tue Aug 14 12:30:57 EDT 2018


Hi,

What is the correct way of setting archiver (and flags) and linker
(and flags) outside the CMakeLists.txt?

1) I am trying to use the following pattern:

cmake -DCMAKE_AR="<path-to-ar>" -DCMAKE_CXX_LINK_EXECUTABLE="<linker
path> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o
<TARGET> <LINK_LIBRARIES>" -DSTATIC_LIBRARY_FLAGS="<flags>"
-DCMAKE_SHARED_LINKER_FLAGS="<flags>"
-DCMAKE_EXE_LINKER_FLAGS="<flags>"

Is that in general correct options to pass that information?
Judging by documentation, they are.

2) However, I am getting the following warning:
CMake Warning:
  Manually-specified variables were not used by the project:

    STATIC_LIBRARY_FLAGS
(Also, in CMakeCache.txt this variable is UNINITIALIZED)

If I am trying to use CMAKE_STATIC_LINKER_FLAGS, I get in the cache:

//Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar
...
//Flags used by the linker during the creation of static libraries.
CMAKE_STATIC_LINKER_FLAGS:STRING=rcsD

But the link command looks like:

/usr/bin/ar qc libXXX.a rcsD file1.o .. filen.o
/usr/bin/ranlib libz.a

and I get the error:
/usr/bin/ar: rcsD: No such file or directory

Because the order of ar arguments is wrong, flags should come before "qc".

Thank you in advance
Irina


Irina Chernushina | Software Developer | ichern at google.com |


Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Halimah DeLaine Prado

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls sie diese fälschlicherweise
erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes
weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich
bitte wissen, dass die E-Mail an die falsche Person gesendet wurde.



This e-mail is confidential. If you received this communication by
mistake, please don't forward it to anyone else, please erase all
copies and attachments, and please let me know that it has gone to the
wrong person.


More information about the CMake mailing list