Monday, May 24, 2010

Adding 64bit support to your C++ program under Linux

By default, Unix's stat struct uses a 4Byte long int for the file size. This will give you a maximum file size of about 4GB (by unsinging the int). In order to support files above that size you need to add the following flags to your MakeFile.

-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64

Since I am using automake, I did this by using the following flags to my configure call:

./configure CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" CXXFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"

No comments: