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

        <legend id='PpwE3'><style id='PpwE3'><dir id='PpwE3'><q id='PpwE3'></q></dir></style></legend>

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

        如何使用 CMake 通过命令行定义 C++ 预处理器宏?

        How to define a C++ preprocessor macro through the command line with CMake?(如何使用 CMake 通过命令行定义 C++ 预处理器宏?)

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

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

                  <tfoot id='UugTE'></tfoot>
                  本文介绍了如何使用 CMake 通过命令行定义 C++ 预处理器宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试在 CMake 的命令行中设置预处理器宏.我试过了:

                  I try to set a preprocessor macro in the command line of CMake. I've tried:

                  set generator="Visual Studio 8 2005"
                  set params=-D MY_MACRO=1
                  cmake.exe -G %generator% %params% ..some_project
                  

                  但它既没有在我编译时定义,也没有在 CMake 生成的文件中找到名称 MY_MACRO,除了 CMakeCache.txt 它存在于形式:

                  but it's neither defined when I compile nor can I find the name MY_MACRO in the files generated by CMake at all, except for CMakeCache.txt where it's present in the form:

                  MY_MACRO:UNINITIALIZED=1
                  

                  我该怎么做?

                  推荐答案

                  这个问题背后的动机是批量构建 3rd 方库,这就是我想避免修改 CMakeLists.txt 的原因.多年后,即使我不再需要它,我发现它很容易通过CMake 外部手段来实现:

                  The motivation behind the question was to batch build 3rd party libraries, which is why I wanted to avoid modifying CMakeLists. So years later, even though I don't need that anymore, I figured out that it's easily achievable by means external to CMake:

                  • 像往常一样调用 CMake,没有特殊标志.

                  • Invoke CMake as usual, no special flags.

                  那么:

                  • 使用 MSVC: 编译器读取 CL 环境变量以获得额外的命令行参数.所以

                  • With MSVC: The compiler reads the CL environment variable to get extra command line arguments. So

                    set CL=/DMY_MACRO=1 %CL%
                  

                  然后调用 MSBuild 来完成它的工作.

                  then invoke MSBuild to do its job.

                  使用 Makefile: 生成的 makefile 使用 CFLAGSCXX_FLAGS 变量作为 makefile 的预期用途.所以构建可以通过

                  With Makefiles: The generated makefiles use the CFLAGS and CXX_FLAGS variables as makefiles are expected to do. So the build can be started by

                    make CXX_FLAGS=-DMY_MACRO=1
                  

                  或者通过设置相应的环境变量.

                  or by setting the corresponding environment variables.

                  这篇关于如何使用 CMake 通过命令行定义 C++ 预处理器宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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?)
                    <bdo id='J2UbH'></bdo><ul id='J2UbH'></ul>
                      <tbody id='J2UbH'></tbody>
                  • <i id='J2UbH'><tr id='J2UbH'><dt id='J2UbH'><q id='J2UbH'><span id='J2UbH'><b id='J2UbH'><form id='J2UbH'><ins id='J2UbH'></ins><ul id='J2UbH'></ul><sub id='J2UbH'></sub></form><legend id='J2UbH'></legend><bdo id='J2UbH'><pre id='J2UbH'><center id='J2UbH'></center></pre></bdo></b><th id='J2UbH'></th></span></q></dt></tr></i><div id='J2UbH'><tfoot id='J2UbH'></tfoot><dl id='J2UbH'><fieldset id='J2UbH'></fieldset></dl></div>

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

                      <legend id='J2UbH'><style id='J2UbH'><dir id='J2UbH'><q id='J2UbH'></q></dir></style></legend>

                            <tfoot id='J2UbH'></tfoot>