本文介绍了未知类型名称'off64_t'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu上使用Apache GCC 4.8.1时遇到问题



问题在于 off64_t 进行编译时,< sys / types.h> 不可用。 (编译时使用 g ++ 一切正常)

有谁知道使用哪个编译器开关来启用 off64_t ? (我知道定义 _LARGEFILE_SOURCE _LARGEFILE64_SOURCE 可以避免这个问题,但是想知道这是否正确)

重现错误可以简单地尝试编译以下代码:

  #include< sys / types.h> 
off64_t a_variable;


解决方案

off64_t不是语言定义的类型。没有编译器开关会使它可用。



它在sys / types.h中定义,但是(在32位系统上)仅当


  • _LARGEFILE64_SOURCE被定义为
    这将使64位接口可用(off64_t,lseek64()等)。
    32位接口仍然可以使用它们的原始名称。

  • _FILE_OFFSET_BITS被定义为'64'

    这将使得(另外的32位)函数和数据类型的名称指向它们的64位对应物。

    off_t将是off64_t,lseek()将使用lseek64()等等。 。
    32位界面不再可用。




确保如果你定义这些宏在程序中的任何地方,你可以在所有源文件的开头定义它们。你不希望ODR违规在你的屁股上咬你。



请注意,这是32位系统,其中off_t通常是32位值。
在64位系统上,接口已经是64位宽,您不需要使用这些宏来获得大文件支持。

off_t是64位类型, lseek()需要64位偏移量,等等。

此外,名称中包含64的类型和函数没有定义,没有意义。



请参阅



您也许有兴趣知道在使用g ++时,_GNU_SOURCE会自动定义,哪个(使用gnu c运行时库)会导致_LARGEFILE64_SOURCE为defiend。这就是为什么用g ++编译测试程序使得off64_t可见的原因。我假设APR在定义_LARGEFILE64_SOURCE时使用了相同的逻辑。


I have a problem using Apache Portable Runtime on Ubuntu with GCC 4.8.1

The problem is that the off64_t from <sys/types.h> is not available when compiling with gcc. (When compiling with g++ everything work fine)

Does anybody know which compiler switch to use to enable off64_t? (I know that defining _LARGEFILE_SOURCE _LARGEFILE64_SOURCE avoids the problem, but wondering if this is the right way)

To reproduce the error one can simply try to compile the following code:

#include <sys/types.h>
off64_t a_variable;
解决方案

off64_t is not a language defined type. No compiler switch will make it available.

It is defined in sys/types.h, but (on a 32 bit system) only if

  • _LARGEFILE64_SOURCE is defined
    Which will make the 64 bit interfaces available (off64_t, lseek64(), etc...).
    The 32 bit interfaces will still be available by their original names.

  • _FILE_OFFSET_BITS is defined as '64'
    Which will make the names of the (otherwise 32 bit) functions and data types refer to their 64 bit counterparts.
    off_t will be off64_t, lseek() will use lseek64(), and so on...
    The 32 bit interface is no longer available.

Make sure that if you define these macros anywhere in your program, you define them at the beginning of all your source files. You don't want ODR violations to be biting you in the ass.

Note, this is for a 32 bit system, where off_t is normally a 32 bit value.
On a 64 bit system, the interface is already 64 bits wide, you don't need to use these macros to get the large file support.
off_t is a 64 bit type, lseek() expects a 64 bit offset, and so on.
Additionally, the types and functions with 64 in their name aren't defined, there's no point.

See http://linux.die.net/man/7/feature_test_macros
and http://en.wikipedia.org/wiki/Large_file_support

You also may be interested to know that when using g++, _GNU_SOURCE is automatically defined, which (with the gnu c runtime library) leads to _LARGEFILE64_SOURCE being defiend. That is why compiling your test program with g++ makes off64_t visible. I assume APR uses the same logic in making _LARGEFILE64_SOURCE defined.

这篇关于未知类型名称'off64_t'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-16 22:31