<tfoot id='XtHXx'></tfoot>

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

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

    • <bdo id='XtHXx'></bdo><ul id='XtHXx'></ul>

      强制 GCC 将 .cpp 文件编译为 C

      时间:2023-10-17
        <bdo id='H6a9J'></bdo><ul id='H6a9J'></ul>

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

            1. <small id='H6a9J'></small><noframes id='H6a9J'>

              <tfoot id='H6a9J'></tfoot>
                <tbody id='H6a9J'></tbody>
                <legend id='H6a9J'><style id='H6a9J'><dir id='H6a9J'><q id='H6a9J'></q></dir></style></legend>

                本文介绍了强制 GCC 将 .cpp 文件编译为 C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个外部提供的 .cpp 文件.它是 C 兼容代码和一些 C++ 的混合体.C++ 代码只是对 C 的封装,以利用 C++ 的特性.

                I have an externally provided .cpp file. It is a mixture of C compatible code and a bit of C++ as well. The C++ code is just a wrapper around the C to take advantage of C++ features.

                它使用 #ifdef __cplusplus 宏来保护 C++ 代码,这很棒.不幸的是,如果我尝试使用 GCC 进行编译,由于文件结尾,它会将其视为 C++.我知道 gccg++ 之间的区别 - 我不想编译为 C++.

                It uses #ifdef __cplusplus macros to protect the C++ code, which is great. Unfortunately, if I try to compile using GCC, it treats it as C++ because of the file ending. I'm aware of the differences between gcc and g++ - I don't want to compile as C++.

                有什么办法可以强制 GCC 将此文件视为 C 文件?我试过使用例如--std=c99,但这会正确地产生 C99 对 C++ 无效的错误.

                Is there any way I can force GCC to treat this file as a C file? I've tried using e.g. --std=c99, but this correctly produces the error that C99 isn't valid for C++.

                将文件重命名为 .c 是可行的,但如果可能的话,我想避免这种情况,因为它是外部提供的,最好将其保留为原始副本.

                Renaming the file to .c works, but I'd like to avoid this if possible because it's externally provided and it'd be nice for it to remain as a pristine copy.

                推荐答案

                gcc-x 选项允许您指定其后的所有输入文件的语言:

                The -x option for gcc lets you specify the language of all input files following it:

                $ gcc -x c your-file-name.cpp
                

                如果你只想对那个文件进行特殊处理,你可以使用 -x none 来关闭特殊处理:

                If you only want to special-case that one file, you can use -x none to shut off the special treatment:

                $ gcc -x c your-filename.cpp -x none other-file-name.cpp
                

                (your-filename.cpp 将编译为 C,而 other-file-name.cpp 将使用扩展名并编译为 C++)

                (your-filename.cpp will be compiled as C, while other-file-name.cpp will use the extension and compile as C++)

                这篇关于强制 GCC 将 .cpp 文件编译为 C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:为什么这个 C++ 包装类没有被内联? 下一篇:如何使用g++编译openmp

                相关文章

              • <small id='QHwSs'></small><noframes id='QHwSs'>

                1. <legend id='QHwSs'><style id='QHwSs'><dir id='QHwSs'><q id='QHwSs'></q></dir></style></legend>

                  1. <tfoot id='QHwSs'></tfoot>

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