Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ system file bits/stat.h suddenly breaks with "error: field ‘st_atim’ has incomplete type"

I'm porting over a large, old system that was known to work, onto Ubuntu 64-bit Linux. The system uses FLTK, upgrading to 1.3.2, and I'm using NetBeans. A file includes basic universal /FL/Fl.H as its first line. This includes the newer unicode enabler /FL/fl_utf8.h. This includes system file <sys/stat.h>, which then includes system file <bits/stat.h>. When wiring this up, and -I including various different directories, all of a sudden the system files break at compile time with:

In file included from /usr/include/sys/stat.h:107,
/usr/include/bits/stat.h:88: error: field ‘st_atim’ has incomplete type
/usr/include/bits/stat.h:89: error: field ‘st_mtim’ has incomplete type
/usr/include/bits/stat.h:90: error: field ‘st_ctim’ has incomplete type
/usr/include/bits/stat.h:149: error: field ‘st_atim’ has incomplete type
/usr/include/bits/stat.h:150: error: field ‘st_mtim’ has incomplete type
/usr/include/bits/stat.h:151: error: field ‘st_ctim’ has incomplete type

Is the latest FLTK not working? Allergic to 64 bits? Internet suggests bug in a system header file? glibc is incompatible? Add _GNU_SOURCE? Don't USE_MISC? Lots of flailing in the blogs, what's going on here?

like image 633
DragonLord Avatar asked Feb 19 '13 00:02

DragonLord


1 Answers

The short answer: Someone, somewhere, has created a random file entitled "time.h". Your include path has included the directory this is in. This is short-circuiting the system in a non-obvious way. The file doesn't even have to be used, it could be a random test scratch file that one of the programmers put together on the side, not incorporated in. It simply has to exist, and be reachable in your greater include path. This will be enough to hose you. Not a FLTK problem at all.

The longer answer: stat.h got upgraded from based on __time_t st_atime etc. to being based on struct timespec st_atim etc. [note missing e on end] for handling nanosecond resolution timestamps. But timespec is defined in the system's time.h. If you include a random time.h somewhere in your path, this shadows the include, wiping out the definition of struct timespec.

Apparently this same issue is also a problem with FFMpeg v1.0 and /include/libavutil.

Bottom line: Insist no one ever makes a file called "time.h".

like image 179
DragonLord Avatar answered Oct 12 '22 12:10

DragonLord