How can I get gcc to write a file larger than 2.0 GB?
Solution 1:
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)
=====================================
Settings
Compiler and Debugger...
[Compiler Settings]
[#defines] ... Add the following
_FILE_OFFSET_BITS="64"
* Using CodeBlocks (for a given Project)
======================================
Properties
Build Options
[Compiler Settings]
[#defines] ... Add the following
_FILE_OFFSET_BITS="64"
* 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
Solution 2:
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.