I wanted to recompile 'xxd' (written in C), so I installed CodeBlocks as the IDE.

All seemed to go well unil I discovered that I couldn't write past the 2.0 GB barrier...

I've read that 'gcc' needs to be recompiled... (That sounds a bit dramatic..)
I've read that I can use 'fread64()' instead of 'fread()' ... (didn't work)
I've read something about a compiler options (?)... but I get lost at that point?

I am surprised that it didn't work out-of-the-box, as I thought the 2.0 GB limit was ancient history as far as defaults go ... wrong again?:(

My OS is 32-bit, on 32-bit hardware.
The gcc version report in as: gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

Is there a simple way around this issue?

PS.. I was fascinated by the WARNINGS: section of 'info xxd' (..only on Linux ;)


A simple #define seems to be all that is needed.. (the program writes past 2 GB now.)

Perhaps the reason it didn't compile apppropriately, is that I compiled a single program from a much larger suite ('xxd' is part of 'vim')...

Had I compiled 'vim' in toto, it would most likely have worked fine...

So for anyone who comes to this page, the following may be of some value:
I assume similar settings would apply to other IDEs.

Adding #defines

* Using CodeBocks (as a global setting)
    Compiler and Debugger...
      [Compiler Settings]
        [#defines] ... Add the following

* Using CodeBlocks (for a given Project)
    Build Options
      [Compiler Settings]
        [#defines] ... Add the following

* Directly into gcc's command line
  gcc -D_FILE_OFFSET_BITS="64"

* Add a #define directly to the source
  #define _FILE_OFFSET_BITS  64  

Also, I discovered this snippet while googling for the solution...
What macros are predefined by gcc? ... in the terminal:

  • touch foo.h; cpp -dM foo.h
  • 1
    Even shorter: cpp -dM /dev/null
    – Kees Cook
    Jan 15 '11 at 5:05
  • cpp -dM <Enter><Ctrl>D ...You got me thinking about what /dev/null adtually does here... and I think I now, also, understand what is happening with cpp.. It must prepend these #defines to all jobs it processes, and in this case the terminal gets tho output instead of the next tool in the pipe; makes sense... There is no magic.. it really is only ones and zeroes... but it surely can look like magic. :) ...
    – Peter.O
    Jan 15 '11 at 10:18

I recommend adding -D_GNU_SOURCE as long as #include <features.h> is used. This will enable all the largefile support. Read the beginning of /usr/include/features.h for more details:

_LARGEFILE_SOURCE    Some more functions for correct standard I/O.
_LARGEFILE64_SOURCE  Additional functionality from LFS for large files.
_FILE_OFFSET_BITS=N  Select default filesystem interface.
_GNU_SOURCE      All of the above, plus GNU extensions.
  • I assume that this is the best GNU way to go about doing it from a fresh start...(which is where most coding situations "start" from).. so it is the best all-round soluton
    – Peter.O
    Jan 23 '11 at 20:46

I had the same issue -- was not able to write a file larger than 2GB. My OS was 64 bit, mount point was jfs2, and my fsize=-1 All I did was change fopen in my program to fopen64 and voila!

  • fopen is an alias of fopen64 on 64-bit platforms. May 17 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.