I would like to know how to fix this error:
error: aggregate 'Padron_Electoral::getFileSize(const char*)::stat stat_buf' has incomplete type and cannot be defined
The method in question is:
long long const Padron_Electoral::getFileSize(const char* filename) {
struct stat stat_buf; // This line doesnt compile en the computer Im currently working on, If tried on another computer this method compiles and work.
int rc = stat(filename, &stat_buf);
return rc == 0 ? stat_buf.st_size : -1;
}
If I comment this method the rest of the code compiles, Im using GNU GCC compiler. Both computers have the same compiler and Im working in Codeblocks. If I try to compile it on console it throws the same error. Has anyone got this same mistake? What could be the reasons and how to fix it?
Code is identical in both computers, #include #include and the include of the .h file
Other errors it throws:
error: invalid use of incomplete type 'struct Padron_Electoral::getFileSize(const char*)::stat'
error: forward declaration of 'struct Padron_Electoral::getFileSize(const char*)::stat'
The #include could be included on the computer where the code compiled but on the other computer the include throws errors:
Build: Debug in Prueba (compiler: GNU GCC Compiler) c:\mingw\include\io.h|301|error: 'off64_t' does not name a type c:\mingw\include\io.h|302|error: 'off64_t' does not name a type c:\mingw\include\unistd.h|65|error: 'off_t' has not been declared| C:\Users\Gabriel\Documents\Progra II\Prueba\main.cpp||In function 'int main()': C:\Users\Gabriel\Documents\Progra II\Prueba\main.cpp|7|error: aggregate 'main()::stat stat_buf' has incomplete type and cannot be defined| C:\Users\Gabriel\Documents\Progra II\Prueba\main.cpp|8|error: invalid use of incomplete type 'struct main()::stat'| C:\Users\Gabriel\Documents\Progra II\Prueba\main.cpp|7|error: forward declaration of 'struct main()::stat' Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Operating system of the computer where the code fails to compile is: Windows 7 Ultimate.
Processor of the computer where the code fails to compile: Intel Core i5 4440 CPU 3.10GHz
MinGW. GCC 4.8.1 (both computers)
IDE: Codeblocks 13.12 (both machines use this IDE)
Both are 64 bit Operating Systems
Operating system of the computer where it compiles and works: Windows 7 Home Premium.
Processor of the computer where it compiles and works: Intel Pentium CPU P6100 2.0GHz
Thank you
Edit: Code compiles now, MinGW32 issue
long long const Padron_Electoral::getFileSize(const char* filename) {
#if __MINGW32__
struct __stat64 stat_buf;
int rc = __stat64(filename, &stat_buf);
return rc == 0 ? stat_buf.st_size : -1;
#else
struct stat stat_buf;
int rc = stat(filename, &stat_buf);
return rc == 0 ? stat_buf.st_size : -1;
#endif
return 0;
}
Question remains on why does MinGW throws an error on this method on one computer and not in the other.