我的程序包含两个外部库的头文件:nifti_io.h
和CImg.h
(分别从here和here下载)。编译器(位于Code :: Blocks内部的GCC 8.2.0)在/usr/include/dirent.h
中返回了这些奇怪的错误-IDE中的生成消息为:
g++ -Wall -fexceptions -O2 -c /tmp/image_test.cpp -o tmp/obj/Release/image_test.o
g++ -o bin/Release/image_test obj/Release/image_test.o -s ../z/libz.so ../znz/bin/Release/libznz.so ../nifti/bin/Release/libnifti.so
In file included from /usr/include/nifti/nifti1_io.h:18,
from /tmp/image_test.cpp:4:
/usr/include/dirent.h:99:5: error: expected identifier before numeric constant
DT_UNKNOWN = 0,
^~~~~~~~~~
/usr/include/dirent.h:99:5: error: expected ‘}’ before numeric constant
In file included from /tmp/CImg.h:173,
from /tmp/image_test.cpp:7:
/usr/include/dirent.h:98:3: note: to match this ‘{’
{
^
In file included from /usr/include/nifti/nifti1_io.h:18,
from /tmp/image_test.cpp:4:
/usr/include/dirent.h:99:5: error: expected unqualified-id before numeric constant
DT_UNKNOWN = 0,
^~~~~~~~~~
In file included from /usr/include/features.h:424,
from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
from /usr/include/stdio.h:27,
from /usr/include/nifti/nifti1_io.h:9,
from /tmp/image_test.cpp:4:
/usr/include/dirent.h:402:1: error: expected declaration before ‘}’ token
__END_DECLS
^~~~~~~~~~~
Process terminated with status 1 (0 minute(s), 0 second(s))
4 error(s), 0 warning(s) (0 minute(s), 0 second(s))
将所有内容注释掉之后(包括这些库的所有程序所做的工作都是int main() { return (0); }
),错误仍然存在。
#include "nifti/nifti1_io.h"
#include "CImg.h"
int main() { return ( 0 ); }
仅包含其中一个(nifti1_io.h
或CImg.h
)进行编译,不会出现错误或警告。包括它们两个都返回上面的输出。
有人知道这是什么原因以及如何解决吗?我的猜测是,它与编译器指令有关,特别是涉及extern "C"
的指令。我想保留包含的头文件,因为它们不是我的。