Thread: O_largefile ???

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    269

    O_largefile ???

    When trying to compile a fairly large program, I get the following:

    Code:
    adios_posix1.c:89: error: ‘O_LARGEFILE’ undeclared (first use in this function)
    adios_posix1.c:89: error: (Each undeclared identifier is reported only once
    adios_posix1.c:89: error: for each function it appears in.)
    Any suggestions? I need to change something in the Makefile, which is also fairly large.

    This is what I'm trying to build:
    National Center for Computational Sciences » ADIOS
    1.2.1

    I honestly can only find unhelpful information via google.

  2. #2
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    I believe O_LARGEFILE is a GNU extension. Add `_GNU_SOURCE' to the defined preprocessor symbols and see if it works.
    Stick close to your desks and never program a thing,
    And you all may sit in the standards commitee!

  3. #3
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by Ronix View Post
    I believe O_LARGEFILE is a GNU extension. Add `_GNU_SOURCE' to the defined preprocessor symbols and see if it works.
    I'm quite new to C. I don't know how to add to defined preprocessor symbols, or what those are.

    Sorry for my ignorance.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Location
    Black River
    Posts
    128
    Add the command `-D_GNU_SOURCE' to your makefile to have it defined. ie: `gcc foo.c' becomes `gcc -D_GNU_SOURCE foo.c'
    Stick close to your desks and never program a thing,
    And you all may sit in the standards commitee!

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    It may be easier to add define (-D_GNU_SOURCE) to your CFLAGS environment variable or the Makefile variable.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  6. #6
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by MWAAAHAAA View Post
    It may be easier to add define (-D_GNU_SOURCE) to your CFLAGS environment variable or the Makefile variable.
    Here's what my CFLAGS environment variable now says

    -D_GNU_SOURCE -fno-common

    (i added the -D_GNU_SOURCE)
    but I still get the same error.... I guess I will try figuring out where exactly in the Makefile I have to put it.

    Edit: I'm unsure of what the makefile variable is?
    Last edited by dayalsoap; 09-15-2010 at 05:24 PM.

  7. #7
    Registered User
    Join Date
    May 2010
    Posts
    269
    I'm too new with C to fully understand where I need to put this -D_GNU_SOURCE. I've attached the Makefile. I'm really sorry for my ignorance.. it will get better....

    Also, in the Makefile, there is :
    CFLAGS = -g -O2 -D_GNU_SOURCE

    I added the -D_GNU_SOURCE

    but I still get the same error
    Last edited by dayalsoap; 09-15-2010 at 05:35 PM.

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    269
    Am I asking incorrectly, or is it something that's not so easy?

  9. #9
    Registered User
    Join Date
    Sep 2007
    Posts
    1,012
    First off, O_LARGEFILE is indeed a GNU extension. If you're not on a system with glibc (which basically means if you're not on Linux), simply get rid of O_LARGEFILE (or read your system's documentation on large file support).

    If you are on Linux, the open(2) man page should tell you about O_LARGEFILE: “(LFS) Allow files whose sizes cannot be represented in an off_t (but can be represented in an off64_t) to be opened. The _LARGEFILE64_SOURCE macro must be defined in order to obtain this definition. Setting the _FILE_OFFSET_BITS feature test macro to 64 (rather than using O_LARGEFILE) is the preferred method of obtaining method of accessing large files on 32-bit systems (see feature_test_macros(7)).”

    The good news is that on Linux, at least, you can magically figure out what you need for large file support via getconf. That is, you don't need to (and probably shouldn't) set _FILE_OFFSET_BITS by hand. On 64-bit systems, I suspect off_t is already 64-bit (but don't quote me, I'm still in 32-bit land). getconf will know what, precisely, is needed on each system. So:
    Code:
    getconf LFS_CFLAGS
    getconf LFS_LDFLAGS
    getconf LFS_LIBS
    will tell you all you need to know about LFS on your system. Once you use the proper defines to get 64-bit file I/O, you should drop the O_LARGEFILE. It's not needed, and, as the man page hints at, obsolescent.

    UPDATE: I suppose O_LARGEFILE is a Linux extension, not GNU. The rest of the post stands, though.
    Last edited by cas; 09-15-2010 at 06:50 PM. Reason: See post.

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    269
    Quote Originally Posted by cas View Post
    First off, O_LARGEFILE is indeed a GNU extension. If you're not on a system with glibc (which basically means if you're not on Linux), simply get rid of O_LARGEFILE (or read your system's documentation on large file support).

    If you are on Linux, the open(2) man page should tell you about O_LARGEFILE: “(LFS) Allow files whose sizes cannot be represented in an off_t (but can be represented in an off64_t) to be opened. The _LARGEFILE64_SOURCE macro must be defined in order to obtain this definition. Setting the _FILE_OFFSET_BITS feature test macro to 64 (rather than using O_LARGEFILE) is the preferred method of obtaining method of accessing large files on 32-bit systems (see feature_test_macros(7)).”

    The good news is that on Linux, at least, you can magically figure out what you need for large file support via getconf. That is, you don't need to (and probably shouldn't) set _FILE_OFFSET_BITS by hand. On 64-bit systems, I suspect off_t is already 64-bit (but don't quote me, I'm still in 32-bit land). getconf will know what, precisely, is needed on each system. So:
    Code:
    getconf LFS_CFLAGS
    getconf LFS_LDFLAGS
    getconf LFS_LIBS
    will tell you all you need to know about LFS on your system. Once you use the proper defines to get 64-bit file I/O, you should drop the O_LARGEFILE. It's not needed, and, as the man page hints at, obsolescent.

    UPDATE: I suppose O_LARGEFILE is a Linux extension, not GNU. The rest of the post stands, though.

    I see. I'm on a Mac, so I guess I will have to figure out where O_LARGEFILE is present and remove it.


    Thank you very much for your help. It's MY fault for not specifying I'm on a Mac.

  11. #11
    Registered User
    Join Date
    May 2010
    Posts
    269
    I removed the O_LARGEFILE in the opens and it now compiles.

    Brilliant.

Popular pages Recent additions subscribe to a feed