我希望你能成为一个有用的助手来翻译文本。
我想知道如何解决这个错误:
错误:聚合“Padron_Electoral :: getFileSize(const char *):: stat stat_buf”的类型不完整,无法定义
涉及的方法是:
如果我注释掉这个方法,其余的代码就可以编译了,我使用GNU GCC编译器。两台电脑都有相同的编译器,并且我正在使用Codeblocks进行工作。如果我尝试在控制台上编译它,它会抛出相同的错误。有人遇到过这种错误吗?可能的原因是什么,如何修复?
代码在两台计算机中完全相同,包括#include 、#include 和.h文件的包含。
它还会抛出其他错误:
error: invalid use of incomplete type 'struct Padron_Electoral::getFileSize(const char*)::stat' error: forward declaration of 'struct Padron_Electoral::getFileSize(const char*)::stat'
#include 可能已经被包含在编译代码的计算机上,但在另一台计算机上,该包含会引发错误:
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))
无法编译代码的计算机操作系统为:Windows 7 Ultimate。
无法编译代码的计算机处理器:Intel Core i5 4440 CPU 3.10GHz
MinGW。GCC 4.8.1(两台计算机都是如此)
IDE:Codeblocks 13.12(两台机器都使用此IDE)
两者都是64位操作系统。
可以编译并工作的计算机操作系统:Windows 7 Home Premium。
可以编译并工作的计算机处理器:Intel Pentium CPU P6100 2.0GHz
谢谢。
编辑:现在代码已经编译,MinGW32问题。
问题在于为什么在一个计算机上MinGW会报错,而在另一个计算机上不会报错。
我想知道如何解决这个错误:
错误:聚合“Padron_Electoral :: getFileSize(const char *):: stat stat_buf”的类型不完整,无法定义
涉及的方法是:
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;
}
如果我注释掉这个方法,其余的代码就可以编译了,我使用GNU GCC编译器。两台电脑都有相同的编译器,并且我正在使用Codeblocks进行工作。如果我尝试在控制台上编译它,它会抛出相同的错误。有人遇到过这种错误吗?可能的原因是什么,如何修复?
代码在两台计算机中完全相同,包括#include 、#include 和.h文件的包含。
它还会抛出其他错误:
error: invalid use of incomplete type 'struct Padron_Electoral::getFileSize(const char*)::stat' error: forward declaration of 'struct Padron_Electoral::getFileSize(const char*)::stat'
#include 可能已经被包含在编译代码的计算机上,但在另一台计算机上,该包含会引发错误:
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))
无法编译代码的计算机操作系统为:Windows 7 Ultimate。
无法编译代码的计算机处理器:Intel Core i5 4440 CPU 3.10GHz
MinGW。GCC 4.8.1(两台计算机都是如此)
IDE:Codeblocks 13.12(两台机器都使用此IDE)
两者都是64位操作系统。
可以编译并工作的计算机操作系统:Windows 7 Home Premium。
可以编译并工作的计算机处理器:Intel Pentium CPU P6100 2.0GHz
谢谢。
编辑:现在代码已经编译,MinGW32问题。
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;
}
问题在于为什么在一个计算机上MinGW会报错,而在另一个计算机上不会报错。
#include <sys/stat.h>
吗? - Brian Bi