【问题标题】:how to compile c++ and not include cstdio and other c standard libraries如何编译c++而不包含cstdio和其他c标准库
【发布时间】:2015-10-02 15:49:50
【问题描述】:

我是一名 C 程序员,具有最少的 C++ 专业知识。我一直在尝试从herehere 下载和安装软件包。我运行configuremake,对于dsr-pdb,我遇到了一些错误,例如

../include/dsrpdb/Point.h:69:14: error: 'assert' was not declared in this scope
assert(i < 3);

对于synaps,我明白了

if g++ -DHAVE_CONFIG_H -I. -I. -I../include/synaps   -I/usr/include -I../include -O3 -g -O2 -MT Variables.o -MD -MP -MF ".deps/Variables.Tpo" -c -o Variables.o `test -f '../mpol/src/Variables.cpp' || echo './'`../mpol/src/Variables.cpp; \
    then mv -f ".deps/Variables.Tpo" ".deps/Variables.Po"; else rm -f ".deps/Variables.Tpo"; exit 1; fi
../mpol/src/Variables.cpp: In member function ‘std::string SYNAPS::Variables::operator[](int)’:
../mpol/src/Variables.cpp:16:25: error: ‘sprintf’ was not declared in this scope 
sprintf(str,"%d",i);

这些是错误,因为它们的源文件中没有 #include &lt;cassert&gt;#include &lt;cstdio&gt;。我觉得奇怪的是两个不同的开发者做了这件事。这让我想知道是否有一个编译器选项可以自动使用适当的 c-header 和库文件,或者他们是在 IDE 中开发的,可以让他们摆脱它?或者也许 autoconf 或 make 做一些上游的事情?

【问题讨论】:

  • 那些开发者的思想不符合标准。
  • IIRC 标准允许标准头文件包含其他标准头文件,因此标准库的不同实现可能会隐式提供 &lt;cstdio&gt;,如果您包含 &lt;iostream&gt;
  • 这与链接无关。它在编译期间失败并且永远不会进入链接阶段。 @melpomene:是的,恕我直言,这很不幸。这意味着可能无法检测到此类错误。
  • 您还必须考虑这个库质量低下的可能性。
  • 我考虑过,但我想给他们怀疑的好处

标签: c++ c header-files autoconf


【解决方案1】:

gcc 有一个-include 选项,可让您从命令行强制包含头文件。见https://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_2.html#SEC11

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 2022-09-26
    • 2018-10-31
    • 2021-12-15
    • 2021-11-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多