0

因此,当谈到 g++ 和 linux 时,我是一个新手,但我正在尝试编译我编写的 C++ 程序,无论出于何种原因,g++ 与我的包含有问题,我得到了数千行C++ 的错误包括文件(如 stdio.h、string.h 等)。我在下面粘贴了一些:

    In file included from /usr/include/stdio.h:75,
             from /usr/include/root/Rtypes.h:33,
             from /usr/include/root/TObject.h:31,
             from /usr/include/root/TNamed.h:26,
             from /usr/include/root/TAxis.h:25,
             from /usr/include/root/TH1.h:25,
             from /usr/include/root/TH1F.h:25,
             from torusMC.cpp:10:
    /usr/include/libio.h: In function ‘int _IO_feof(_IO_FILE*)’:
    /usr/include/libio.h:462: error: expected primary-expression before ‘,’ token
    /usr/include/libio.h:462: error: ‘printf’ was not declared in this scope
    /usr/include/libio.h:462: error: ‘exit’ was not declared in this scope
    /usr/include/libio.h: In function ‘int _IO_ferror(_IO_FILE*)’:
    /usr/include/libio.h:463: error: expected primary-expression before ‘,’ token
    /usr/include/libio.h:463: error: ‘printf’ was not declared in this scope
    /usr/include/libio.h:463: error: ‘exit’ was not declared in this scope

真正奇怪的是,我之前对不同目录中的不同程序使用了完全相同的包含,并且一切(仍然)编译得很好。如果我将它们全部注释掉,并且使用包含的代码,它编译得很好;如果我使用包含注释的代码保留代码,但即使在其中一个包含中进行注释,我也会再次收到所有错误。

我的环境是否有问题导致它在这个目录中失败?

4

1 回答 1

1

最可能的原因:您在#include之前使用另一个标题TH1F.h,而在另一个标题中,您缺少分号,例如

// some other header
struct Foo {
....
}
 ^ missing ;
于 2012-04-10T03:28:55.283 回答