1. <small id='6fKEm'></small><noframes id='6fKEm'>

    2. <i id='6fKEm'><tr id='6fKEm'><dt id='6fKEm'><q id='6fKEm'><span id='6fKEm'><b id='6fKEm'><form id='6fKEm'><ins id='6fKEm'></ins><ul id='6fKEm'></ul><sub id='6fKEm'></sub></form><legend id='6fKEm'></legend><bdo id='6fKEm'><pre id='6fKEm'><center id='6fKEm'></center></pre></bdo></b><th id='6fKEm'></th></span></q></dt></tr></i><div id='6fKEm'><tfoot id='6fKEm'></tfoot><dl id='6fKEm'><fieldset id='6fKEm'></fieldset></dl></div>
      <tfoot id='6fKEm'></tfoot>

    3. <legend id='6fKEm'><style id='6fKEm'><dir id='6fKEm'><q id='6fKEm'></q></dir></style></legend>

          <bdo id='6fKEm'></bdo><ul id='6fKEm'></ul>

        CMAKE 中添加 -fPIC 编译器选项的惯用方法是什么?

        时间:2023-08-28

        <small id='OWcCH'></small><noframes id='OWcCH'>

        • <bdo id='OWcCH'></bdo><ul id='OWcCH'></ul>
          <tfoot id='OWcCH'></tfoot>

        • <i id='OWcCH'><tr id='OWcCH'><dt id='OWcCH'><q id='OWcCH'><span id='OWcCH'><b id='OWcCH'><form id='OWcCH'><ins id='OWcCH'></ins><ul id='OWcCH'></ul><sub id='OWcCH'></sub></form><legend id='OWcCH'></legend><bdo id='OWcCH'><pre id='OWcCH'><center id='OWcCH'></center></pre></bdo></b><th id='OWcCH'></th></span></q></dt></tr></i><div id='OWcCH'><tfoot id='OWcCH'></tfoot><dl id='OWcCH'><fieldset id='OWcCH'></fieldset></dl></div>

                <tbody id='OWcCH'></tbody>
            • <legend id='OWcCH'><style id='OWcCH'><dir id='OWcCH'><q id='OWcCH'></q></dir></style></legend>

                  本文介绍了CMAKE 中添加 -fPIC 编译器选项的惯用方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了至少 3 种方法来做到这一点,我想知道哪种是惯用的方法.这几乎对任何静态库都需要完成.我很惊讶 CMake 中的 Makefile 生成器不会自动将它添加到静态库中.(除非我遗漏了什么?)

                  I've come across at least 3 ways to do this and I'm wondering which is the idiomatic way. This needs to be done almost universally to any static library. I'm surprised that the Makefile generator in CMake doesn't automatically add this to static libraries. (unless I'm missing something?)

                  target_compile_options(myLib PRIVATE -fPIC)
                  
                  add_compile_options(-fPIC)
                  
                  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fpic")
                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpic")
                  

                  我相信可能还有其他变化.(如果你找到了,请编辑我的问题)

                  I believe there might also be other variations. (please edit my question if you find one)

                  如果您碰巧知道这个问题的答案,您是否也知道是否有一种方法可以在不修改其 CMakeLists.txt 文件的情况下使用此标志编译 3rd 方 CMake 项目?我遇到过缺少该标志的静态库.将静态库编译为动态库时会导致问题.

                  If you happen to know the answer to this question, do you also know if there is a way to cause a 3rd party CMake project to be compiled with this flag without modifying its CMakeLists.txt file? I have run across static libraries missing that flag. It causes problems when compiling a static library into a dynamic library.

                  你得到:

                  relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
                  

                  推荐答案

                  您可以在所有目标上设置位置无关代码属性:

                  You can set the position independent code property on all targets:

                  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
                  

                  或在特定库中:

                  add_library(lib1 lib1.cpp)
                  set_property(TARGET lib1 PROPERTY POSITION_INDEPENDENT_CODE ON)
                  

                  参考:CMAKE_POSITION_INDEPENDENT_CODE cmake 构建系统

                  这篇关于CMAKE 中添加 -fPIC 编译器选项的惯用方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 CMake 中更改 CMAKE_CXX_FLAGS_DEBUG 和朋友的默认值 下一篇:CMake 链接到 Windows 上的共享库:关于找不到 .lib 文件的错误

                  相关文章

                  <tfoot id='6qLgN'></tfoot>

                    <bdo id='6qLgN'></bdo><ul id='6qLgN'></ul>
                    <legend id='6qLgN'><style id='6qLgN'><dir id='6qLgN'><q id='6qLgN'></q></dir></style></legend>

                    <i id='6qLgN'><tr id='6qLgN'><dt id='6qLgN'><q id='6qLgN'><span id='6qLgN'><b id='6qLgN'><form id='6qLgN'><ins id='6qLgN'></ins><ul id='6qLgN'></ul><sub id='6qLgN'></sub></form><legend id='6qLgN'></legend><bdo id='6qLgN'><pre id='6qLgN'><center id='6qLgN'></center></pre></bdo></b><th id='6qLgN'></th></span></q></dt></tr></i><div id='6qLgN'><tfoot id='6qLgN'></tfoot><dl id='6qLgN'><fieldset id='6qLgN'></fieldset></dl></div>

                      <small id='6qLgN'></small><noframes id='6qLgN'>