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 编译器选项的惯用方法是什么?

        What is the idiomatic way in CMAKE to add the -fPIC compiler option?(CMAKE 中添加 -fPIC 编译器选项的惯用方法是什么?)

        <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 编译器选项的惯用方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                  <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>
                          <tbody id='6qLgN'></tbody>

                          <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'>