红联Linux门户
Linux帮助

linux c之关于Value too large for defined data type的解决

发布时间:2017-02-18 15:23:24来源:linux网站作者:yunshouhu
//#define _FILE_OFFSET_BITS 64
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
//stat file >2G
//Error calling stat: Value too large for defined data type
//http://stackoverflow.com/questions/13893580/calling-stat-from-sys-stat-h-faills-with-value-too-large-for-defined-data-typ
int main(int argc, const char *argv[])
{
struct stat st;
#ifdef _FILE_OFFSET_BITS
printf("_FILE_OFFSET_BITS=%d\n",_FILE_OFFSET_BITS);
#endif
if (stat(argv[1], &st) != 0)
{
perror("Error calling stat");
}
printf("stat ok\n");
return 0;
}
 
当stat file >2G 在Linux会出现
Error calling stat: Value too large for defined data type
 
解决方法是:
#define _FILE_OFFSET_BITS 64
#include <sys/stat.h>
 
qt pro配置
TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.c
#http://stackoverflow.com/questions/3348711/add-a-define-to-qmake-with-a-value
# gcc -D_FILE_OFFSET_BITS=64
DEFINES += "_FILE_OFFSET_BITS=64"
include(deployment.pri)
qtcAddDeployment()
 
本文永久更新地址:http://www.linuxdiyf.com/linux/28521.html