我的程序包括两个外部库的头文件:nifti_io.h
和CImg.h
(分别从此处和此处下载)。编译器(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"
. 我想保持包含的头文件完整,因为它们不是我的。