Can I skip cmake compiler tests or avoid “error: unrecognized option '-rdynamic'”

前端 未结 5 1486
[愿得一人]
[愿得一人] 2021-02-02 08:11

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.         


        
相关标签:
5条回答
  • 2021-02-02 08:36

    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 "")
    
    0 讨论(0)
  • 2021-02-02 08:44

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

    set(CMAKE_C_COMPILER_WORKS 1)
    
    0 讨论(0)
  • 2021-02-02 08:47

    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.

    0 讨论(0)
  • 2021-02-02 08:48

    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)
    
    0 讨论(0)
  • 2021-02-02 08:49

    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.

    0 讨论(0)
提交回复
热议问题