Can I skip cmake compiler tests or avoid "error: unrecognized option '-rdynamic'"
Asked Answered
F

5

44

compilation options for cmake (on windows) for ARM target system but when I run configure it's starting compiler tests:

CMake Error at D:/Program Files/CMake 2.8/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
  The C compiler "D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe" is not
  able to compile a simple test program.

  It fails with the following output:

   Change Dir: D:/merge/complex/build/CMakeFiles/CMakeTmp



  Run Build Command:D:/PROGRA~1/YAGART~1/bin/make.exe "cmTryCompileExec/fast"

  D:/PROGRA~1/YAGART~1/bin/make.exe -f
  CMakeFiles/cmTryCompileExec.dir/build.make
  CMakeFiles/cmTryCompileExec.dir/build

  make.exe[1]: Entering directory
  `D:/merge/complex/build/CMakeFiles/CMakeTmp'

  "D:/Program Files/CMake 2.8/bin/cmake.exe" -E cmake_progress_report
  D:/merge/complex/build/CMakeFiles/CMakeTmp/CMakeFiles 1

  Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

  "D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe" -o
  CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
  D:/merge/complex/build/CMakeFiles/CMakeTmp/testCCompiler.c

  Linking C executable cmTryCompileExec

  "D:/Program Files/yagarto/bin/arm-none-eabi-gcc.exe"
  "CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o" -o cmTryCompileExec
  -rdynamic 

  arm-none-eabi-gcc.exe: error: unrecognized option '-rdynamic'

  make.exe[1]: *** [cmTryCompileExec] Error 1

Using Yagatdo 4.6.* cross-compilation toolchain

How can I skip this tests or fix -rdynamic error that I am getting?

Finegrained answered 15/5, 2012 at 10:42 Comment(0)
M
35

You can skip the compiler checks by adding NONE to your project call:

project(<projectname> NONE)

but this can have pretty far-reaching effects. For full details, run

cmake --help-command project

I'm not familiar with ARM, so this is probably not your best option here. I guess you'd be better to see if there's a way to fix the -rdynamic flag.

EDIT:

It looks like this was identified as a bug which is effectively still unresolved. The comments in the bug report mention adding the following lines as a workaround (presumably before your project call):

set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
Marchelle answered 15/5, 2012 at 11:8 Comment(8)
so yagarto is most sane arm compiler afaik, I don't understand why "simple program" request this special.Finegrained
@Sholy I just updated the answer - hope this fixes it for you.Marchelle
I see but I'm getting same output with this sadly :(Finegrained
@Sholy - OK, here's my last guess :-) Try looking at this thread, but note that the settings should be done before the project call.Marchelle
to be honest it's still trying to test... but thank you now I think I have enough info for research.Finegrained
The best answer is found below: set(CMAKE_C_COMPILER_WORKS 1)Pheon
These other answers should be cleaned out as they are obsolete and create confusion.Pheon
@Pheon The answer that you refer to recommends to skip the tests. If someone is cross-compiling they don't necessarily want to skip the tests. They might only want to prevent the addition of the -rdynamic flag. The answers together sketch the most complete picture.Shakespeare
C
42

You can set CMAKE_<LANG>_COMPILER_WORKS to true to suppress further compiler checks for that language.

set(CMAKE_C_COMPILER_WORKS 1)
Communalize answered 4/6, 2015 at 11:2 Comment(1)
You may also need to add a matching "CMAKE_CXX_COMPILER_WORKS" line. This worked for me in a case where for a particular cross-compilation target CMake insisted on using the wrong library path and failed to link the test executable, but picked up the right path for real builds.Epanodos
M
35

You can skip the compiler checks by adding NONE to your project call:

project(<projectname> NONE)

but this can have pretty far-reaching effects. For full details, run

cmake --help-command project

I'm not familiar with ARM, so this is probably not your best option here. I guess you'd be better to see if there's a way to fix the -rdynamic flag.

EDIT:

It looks like this was identified as a bug which is effectively still unresolved. The comments in the bug report mention adding the following lines as a workaround (presumably before your project call):

set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
Marchelle answered 15/5, 2012 at 11:8 Comment(8)
so yagarto is most sane arm compiler afaik, I don't understand why "simple program" request this special.Finegrained
@Sholy I just updated the answer - hope this fixes it for you.Marchelle
I see but I'm getting same output with this sadly :(Finegrained
@Sholy - OK, here's my last guess :-) Try looking at this thread, but note that the settings should be done before the project call.Marchelle
to be honest it's still trying to test... but thank you now I think I have enough info for research.Finegrained
The best answer is found below: set(CMAKE_C_COMPILER_WORKS 1)Pheon
These other answers should be cleaned out as they are obsolete and create confusion.Pheon
@Pheon The answer that you refer to recommends to skip the tests. If someone is cross-compiling they don't necessarily want to skip the tests. They might only want to prevent the addition of the -rdynamic flag. The answers together sketch the most complete picture.Shakespeare
S
29

It seems you target actually something else than Linux, so you should tell cmake that you are cross-compiling for the generic case:

SET(CMAKE_SYSTEM_NAME Generic)

Followed by (optionally, but nice to specify):

SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_CROSSCOMPILING 1)

However, if you specify (which you likely did because this is stated in a lot of examples online):

SET(CMAKE_SYSTEM_NAME Linux)

Then cmake will load the configuration files from (suppose version 2.8) the file:

/usr/share/cmake-2.8/Modules/Platform/Linux.cmake

from which it is likely to load:

/usr/share/cmake-2.8/Modules/Platform/Linux-GNU.cmake

Here the -rdynamic flag is set for historical reasons:

macro(__linux_compiler_gnu lang)
  # We pass this for historical reasons.  Projects may have
  # executables that use dlopen but do not set ENABLE_EXPORTS.
  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS "-rdynamic")
endmacro()

Rather than disabling the tests as indeed is done by specifying NONE as the PROJECT argument, it seems setting the CMAKE_SYSTEM_NAME (to something else than Linux, for instance Generic) is what you actually want to do.

Shakespeare answered 18/7, 2014 at 14:56 Comment(1)
This fixed the problem for me. The trouble with setting CMAKE_SHARED_LIBRARY_LINK_C_FLAGS is that -rdynamic is added even when we're just linking an executable with no shared libraries involved. But changing the system name to something other than Linux worked.Salubrious
H
7

If you're just compiling a static library and you want to avoid having CMake test that the compiler can generate binaries, you can set the variable CMAKE_TRY_COMPILE_TARGET_TYPE.

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
Hyaloid answered 22/2, 2019 at 10:19 Comment(0)
S
1

When cross compiling for Windows, where there is no -rdynamic option, you can use

-DCMAKE_SYSTEM_NAME="Windows"

with cmake. Then Cmake will skip the test with -rdynamic.

Sherylsheryle answered 15/9, 2020 at 11:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.