Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 ;)

share|improve this question

2 Answers 2

up vote 1 down vote accepted

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.
share|improve this answer
    
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

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
share|improve this answer
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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