Problems compiling hdf5 under MingW: undefined reference to 'ftruncated64'

Hi,

I'm having some trouble getting either the latest version 1.8.8 or the
pre-release 1.8.9 HDF5 to compile under Windows 7 64-bit using the latest
version of MingW. The error occurs when linking the library:

  CC H5Z.lo
  CC H5Zdeflate.lo
  CC H5Zfletcher32.lo
  CC H5Znbit.lo
  CC H5Zshuffle.lo
  CC H5Zszip.lo
  CC H5Zscaleoffset.lo
  CC H5Ztrans.lo
  CCLD libhdf5.la
Creating library file: .libs/libhdf5.dll.a
.libs/H5FDstdio.o:H5FDstdio.c:(.text+0x1520): undefined reference to
`ftruncate64'
collect2: ld returned 1 exit status
make[2]: *** [libhdf5.la] Error 1
make[2]: Leaving directory `/c/hdf5-1.8.9-pre1/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/c/hdf5-1.8.9-pre1/src'
make: *** [all-recursive] Error 1

The basic steps I followed was to download and unpack the tar.gz and
runconfigure --enable-cxx followed by make.

I then tried again following the instructions at:

http://www.hdfgroup.org/ftp/HDF5/current/src/unpacked/release_docs/INSTALL_MinGW.txt

and unfortunately got the same results.

Thanks for any help.

Does your src/H5pubconf.h contain:

/* Define to 1 if you have the `ftruncate64' function. */
#define H5_HAVE_FTRUNCATE64 1

That's what I got with my version of 64-bit MinGW - and that seems correct.

My unistd.h contains:
int ftruncate64(int, off64_t);

Just check that your unistd.h does the same. (I have one of the automated builds of gcc-4.7.0.)

I had some trouble with 32-bit MinGW in relation to 'ftruncate64', but not with 64-bit MinGW.

Cheers,
Rob

···

----- Original Message ----- From: "Joseph Slagel"

CCLD libhdf5.la
Creating library file: .libs/libhdf5.dll.a
.libs/H5FDstdio.o:H5FDstdio.c:(.text+0x1520): undefined reference to
`ftruncate64'

Tx for the help. I happen to be using 32-bit MinGW and the define is
commented out in my src/H5pubconf.h. Not surprisingly ftruncate64 isn't in
my unistd.h.

-Joe

···

On Fri, Apr 20, 2012 at 7:32 AM, Sisyphus <sisyphus1@optusnet.com.au> wrote:

----- Original Message ----- From: "Joseph Slagel"

  CCLD libhdf5.la

Creating library file: .libs/libhdf5.dll.a
.libs/H5FDstdio.o:H5FDstdio.c:**(.text+0x1520): undefined reference to
`ftruncate64'

Does your src/H5pubconf.h contain:

/* Define to 1 if you have the `ftruncate64' function. */
#define H5_HAVE_FTRUNCATE64 1

That's what I got with my version of 64-bit MinGW - and that seems correct.

My unistd.h contains:
int ftruncate64(int, off64_t);

Just check that your unistd.h does the same. (I have one of the automated
builds of gcc-4.7.0.)

I had some trouble with 32-bit MinGW in relation to 'ftruncate64', but not
with 64-bit MinGW.

Cheers,
Rob

______________________________**_________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/**mailman/listinfo/hdf-forum_**hdfgroup.org<http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org>

undefinedreference to 'ftruncated64'

Tx for the help. I happen to be using 32-bit MinGW and the define is
commented out in my src/H5pubconf.h. Not surprisingly ftruncate64 isn't in
my unistd.h.

Sorry - my mistake. I misread your post as implying that you were using 64-bit MinGW.

To get around the ftruncate64 problems with 32-bit MinGW I used the attached patch to src\H5FDdirect.c, src\H5FDmpiposix.c, and src\H5FDstdio.c. (It worked well enough for me.)

Building with './configure' I also had to apply some other patches to other files (to deal with problems with 'mkdir' and 'sleep') - which I can provide if necessary.

Cheers,
Rob

pre1.diff (1.39 KB)

···

----- Original Message ----- From: "Joseph Slagel" <Joseph.Slagel@systemsbiology.org>
To: "HDF Users Discussion List" <hdf-forum@hdfgroup.org>
Sent: Saturday, April 21, 2012 7:57 AM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:

I believe the upcoming release HDF5 1.8.9 fixes the issues mentioned. If you
all could try the pre-release tarball to verify the fixes?

Allen

···

On Sunday, April 22, 2012 12:20:15 AM Sisyphus wrote:

----- Original Message -----
From: "Joseph Slagel" <Joseph.Slagel@systemsbiology.org>
To: "HDF Users Discussion List" <hdf-forum@hdfgroup.org>
Sent: Saturday, April 21, 2012 7:57 AM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
undefinedreference to 'ftruncated64'

> Tx for the help. I happen to be using 32-bit MinGW and the define is
> commented out in my src/H5pubconf.h. Not surprisingly ftruncate64 isn't
> in
> my unistd.h.

Sorry - my mistake. I misread your post as implying that you were using
64-bit MinGW.

To get around the ftruncate64 problems with 32-bit MinGW I used the attached
patch to src\H5FDdirect.c, src\H5FDmpiposix.c, and src\H5FDstdio.c. (It
worked well enough for me.)

Building with './configure' I also had to apply some other patches to other
files (to deal with problems with 'mkdir' and 'sleep') - which I can provide
if necessary.

Cheers,
Rob

undefinedreference to 'ftruncated64'

I believe the upcoming release HDF5 1.8.9 fixes the issues mentioned. If you
all could try the pre-release tarball to verify the fixes?

I was using 1.8.9-pre1, and I think the op tried the same.

Cheers,
Rob

···

----- Original Message ----- From: "Allen D Byrne" <byrn@hdfgroup.org>
To: <hdf-forum@hdfgroup.org>
Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
Sent: Tuesday, April 24, 2012 1:32 AM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:

OK, the issues reported should have been addressed. I will double check my
coding, but there should be #ifdef blocks around these issues just for MinGW.
Could you check the code - maybe the #ifdef test is incorrect or the value
being tested is wrong in the generated header?

Thanks,
     Allen

···

On Tuesday, April 24, 2012 07:03:46 PM Sisyphus wrote:

----- Original Message -----
From: "Allen D Byrne" <byrn@hdfgroup.org>
To: <hdf-forum@hdfgroup.org>
Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
Sent: Tuesday, April 24, 2012 1:32 AM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
undefinedreference to 'ftruncated64'

>I believe the upcoming release HDF5 1.8.9 fixes the issues mentioned. If
>you
>
> all could try the pre-release tarball to verify the fixes?

I was using 1.8.9-pre1, and I think the op tried the same.

Cheers,
Rob

I checked the code, there is an define H5_HAVE_MINGW that must be set. Are you
using CMake or configure-make to build the libraries?

CMake should set this variable, but configure would need help to set this
externally.

Allen

···

On Tuesday, April 24, 2012 08:33:41 AM Allen D Byrne wrote:

OK, the issues reported should have been addressed. I will double check my
coding, but there should be #ifdef blocks around these issues just for
MinGW. Could you check the code - maybe the #ifdef test is incorrect or
the value being tested is wrong in the generated header?

Thanks,
     Allen

On Tuesday, April 24, 2012 07:03:46 PM Sisyphus wrote:
> ----- Original Message -----
> From: "Allen D Byrne" <byrn@hdfgroup.org>
> To: <hdf-forum@hdfgroup.org>
> Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
> Sent: Tuesday, April 24, 2012 1:32 AM
> Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
> undefinedreference to 'ftruncated64'
>
> >I believe the upcoming release HDF5 1.8.9 fixes the issues mentioned. If
> >you
> >
> > all could try the pre-release tarball to verify the fixes?
>
> I was using 1.8.9-pre1, and I think the op tried the same.
>
> Cheers,
> Rob

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

Using configure-make to build hdf5. And I was using the pre-release.

···

On Tue, Apr 24, 2012 at 6:41 AM, Allen D Byrne <byrn@hdfgroup.org> wrote:

I checked the code, there is an define H5_HAVE_MINGW that must be set. Are
you
using CMake or configure-make to build the libraries?

CMake should set this variable, but configure would need help to set this
externally.

Allen

On Tuesday, April 24, 2012 08:33:41 AM Allen D Byrne wrote:
> OK, the issues reported should have been addressed. I will double check
my
> coding, but there should be #ifdef blocks around these issues just for
> MinGW. Could you check the code - maybe the #ifdef test is incorrect or
> the value being tested is wrong in the generated header?
>
> Thanks,
> Allen
>
> On Tuesday, April 24, 2012 07:03:46 PM Sisyphus wrote:
> > ----- Original Message -----
> > From: "Allen D Byrne" <byrn@hdfgroup.org>
> > To: <hdf-forum@hdfgroup.org>
> > Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
> > Sent: Tuesday, April 24, 2012 1:32 AM
> > Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
> > undefinedreference to 'ftruncated64'
> >
> > >I believe the upcoming release HDF5 1.8.9 fixes the issues mentioned.
If
> > >you
> > >
> > > all could try the pre-release tarball to verify the fixes?
> >
> > I was using 1.8.9-pre1, and I think the op tried the same.
> >
> > Cheers,
> > Rob
>
> _______________________________________________
> Hdf-forum is for HDF software users discussion.
> Hdf-forum@hdfgroup.org
> http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@hdfgroup.org
http://mail.hdfgroup.org/mailman/listinfo/hdf-forum_hdfgroup.org

undefinedreference to 'ftruncated64'

(I build with configure, not cmake.)

I checked the code, there is an define H5_HAVE_MINGW that must be set.

Should H5_HAVE_WIN32_API also be set for MinGW ? I gather it *should* be defined, but I don't know whether it is. How do I check ?

Similarly, how do I tell whether H5_HAVE_MINGW is defined for my build ?
"H5_HAVE_MINGW" is a bit of a mystery - I can't find it in any of the source header files, and the only src/*.c file that references it is H5FDstdio.c.
In that file we find:

#ifdef H5_HAVE_WIN32_API
#ifndef H5_HAVE_MINGW
    #define file_fseek _fseeki64
    #define file_offset_t __int64
    #define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */
    #define file_ftell _ftelli64
#endif /* H5_HAVE_MINGW */
#endif /* H5_HAVE_WIN32_API */

Quite clearly, if we're running MinGW then the intention is that none of those defines should be set - and I find that none of those defines are set. So that part is fine. (Mind you, I presently don't know if they're unset because H5_HAVE_WIN32_API is not defined for me, or because H5_HAVE_MINGW *is* defined for me.)

The problem with H5FDstdio.c occurs in the very next block of defines:

#ifndef file_fseek
    #ifdef H5_HAVE_FSEEKO64
        #define file_fseek fseeko64
        #define file_offset_t off64_t
        #define file_ftruncate ftruncate64
        #define file_ftell ftello64
    #else
        #define file_fseek fseeko
        #define file_offset_t off_t
        #define file_ftruncate ftruncate
        #define file_ftell ftello
    #endif /* H5_HAVE_FSEEKO64 */
#endif /* file_fseek */

It assumes that if H5_HAVE_FSEEKO64 is defined, then H5_HAVE_FTRUNCATE64 is also defined.

The assumption is correct for my 64-bit MinGW (gcc-4.7.0), but not for my 32-bit MinGW (gcc-4.5.2).

Similarly, both H5FDdirect.c and H5FDmpiposix.c assume that if H5_HAVE_LSEEK64 is defined, then H5_HAVE_FTRUNCATE64 is also defined - which is again true for my 64-bit MinGW, but not for my 32-bit MinGW.

Cheers,
Rob

···

----- Original Message ----- From: "Allen D Byrne" <byrn@hdfgroup.org>
To: <hdf-forum@hdfgroup.org>
Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
Sent: Tuesday, April 24, 2012 11:41 PM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:

Rob,

   The defines should be in the generated H5pubconf.h file. However, because I
could only successfully test CMake on MinGW, I did not want to insert MinGW
checks into configure and not be able to verify them. End result is that those
defines must be added to your H5pubconf.h. Also those defines are needed by
src/H5win32defs.h so that all the proper defines are set before the defines in
H5private.h/H5public.h.

Allen

···

On Wednesday, April 25, 2012 12:26:27 PM Sisyphus wrote:

----- Original Message -----
From: "Allen D Byrne" <byrn@hdfgroup.org>
To: <hdf-forum@hdfgroup.org>
Cc: "Sisyphus" <sisyphus1@optusnet.com.au>
Sent: Tuesday, April 24, 2012 11:41 PM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
undefinedreference to 'ftruncated64'

(I build with configure, not cmake.)

>I checked the code, there is an define H5_HAVE_MINGW that must be set.

Should H5_HAVE_WIN32_API also be set for MinGW ? I gather it *should* be
defined, but I don't know whether it is. How do I check ?

Similarly, how do I tell whether H5_HAVE_MINGW is defined for my build ?
"H5_HAVE_MINGW" is a bit of a mystery - I can't find it in any of the source
header files, and the only src/*.c file that references it is H5FDstdio.c.
In that file we find:

#ifdef H5_HAVE_WIN32_API
#ifndef H5_HAVE_MINGW
    #define file_fseek _fseeki64
    #define file_offset_t __int64
    #define file_ftruncate _chsize_s /* Supported in VS 2005 or newer */
    #define file_ftell _ftelli64
#endif /* H5_HAVE_MINGW */
#endif /* H5_HAVE_WIN32_API */

Quite clearly, if we're running MinGW then the intention is that none of
those defines should be set - and I find that none of those defines are set.
So that part is fine. (Mind you, I presently don't know if they're unset
because H5_HAVE_WIN32_API is not defined for me, or because H5_HAVE_MINGW
*is* defined for me.)

The problem with H5FDstdio.c occurs in the very next block of defines:

#ifndef file_fseek
    #ifdef H5_HAVE_FSEEKO64
        #define file_fseek fseeko64
        #define file_offset_t off64_t
        #define file_ftruncate ftruncate64
        #define file_ftell ftello64
    #else
        #define file_fseek fseeko
        #define file_offset_t off_t
        #define file_ftruncate ftruncate
        #define file_ftell ftello
    #endif /* H5_HAVE_FSEEKO64 */
#endif /* file_fseek */

It assumes that if H5_HAVE_FSEEKO64 is defined, then H5_HAVE_FTRUNCATE64 is
also defined.

The assumption is correct for my 64-bit MinGW (gcc-4.7.0), but not for my
32-bit MinGW (gcc-4.5.2).

Similarly, both H5FDdirect.c and H5FDmpiposix.c assume that if
H5_HAVE_LSEEK64 is defined, then H5_HAVE_FTRUNCATE64 is also defined - which
is again true for my 64-bit MinGW, but not for my 32-bit MinGW.

Cheers,
Rob

undefinedreference to 'ftruncated64'

Rob,

  The defines should be in the generated H5pubconf.h file. However, because I
could only successfully test CMake on MinGW, I did not want to insert MinGW
checks into configure and not be able to verify them. End result is that those
defines must be added to your H5pubconf.h.

Yep - if I manually add defines for both H5_HAVE_WIN32_API and H5_HAVE_MINGW to H5pubconf.h, 1.8.9-pre1 then builds fine for me without the need to patch any files.

That's no so bad .... better if there were some way to get something like the following automatically added to the end of H5pubconf.h:

#ifndef H5_HAVE_WIN32_API
#ifdef WIN32 /* defined for all windows systems */
#define H5_HAVE_WIN32_API 1
#endif

#ifndef H5_HAVE_MINGW
#ifdef __MINGW32__ /*defined for all MinGW compilers */
#define H5_HAVE_MINGW 1
#endif

But if that can't be done easily, then I wouldn't bother about it.

Cheers,
Rob

···

----- Original Message ----- From: "Allen D Byrne" <byrn@hdfgroup.org>
To: "Sisyphus" <sisyphus1@optusnet.com.au>
Cc: <hdf-forum@hdfgroup.org>
Sent: Wednesday, April 25, 2012 11:12 PM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:

Rob,

We will be planning the work for the next release in a week and I will propose
we add these issues to the configure development.

Would you please send your environment information, because I could not get
our MinGW machine (the latest download available a month back) configure to
properly generate the H5pubconf.h file (no changes to defines - just copied).

From my searching, it seems to happen often, but I could not find any solution.

Worst case, I might need to work with you for testing (send you a private
snapshot) our changes?

Allen

···

On Friday, April 27, 2012 04:27:54 PM Sisyphus wrote:

----- Original Message -----
From: "Allen D Byrne" <byrn@hdfgroup.org>
To: "Sisyphus" <sisyphus1@optusnet.com.au>
Cc: <hdf-forum@hdfgroup.org>
Sent: Wednesday, April 25, 2012 11:12 PM
Subject: Re: [Hdf-forum] Problems compiling hdf5 under MingW:
undefinedreference to 'ftruncated64'

> Rob,
>
> The defines should be in the generated H5pubconf.h file. However,
>
> because I
> could only successfully test CMake on MinGW, I did not want to insert
> MinGW
> checks into configure and not be able to verify them. End result is that
> those
> defines must be added to your H5pubconf.h.

Yep - if I manually add defines for both H5_HAVE_WIN32_API and H5_HAVE_MINGW
to H5pubconf.h, 1.8.9-pre1 then builds fine for me without the need to
patch any files.

That's no so bad .... better if there were some way to get something like
the following automatically added to the end of H5pubconf.h:

#ifndef H5_HAVE_WIN32_API
#ifdef WIN32 /* defined for all windows systems */
#define H5_HAVE_WIN32_API 1
#endif
#endif

#ifndef H5_HAVE_MINGW
#ifdef __MINGW32__ /*defined for all MinGW compilers */
#define H5_HAVE_MINGW 1
#endif
#endif

But if that can't be done easily, then I wouldn't bother about it.

Cheers,
Rob

Would you please send your environment information,

Processor is:
AMD Athlon 64 X2 Dual Core Processor 4600+ 2.40GHz

OS is Windows Vista Business (64 bit).

My MinGW/MSYS installation was acquired by downloading (and then running)
mingw-get-inst-20110802.exe

Rob@desktop2 ~
$ uname -a
MINGW32_NT-6.0 DESKTOP2 1.0.17(0.48/3/2) 2011-04-24 23:39 i686 Msys

Rob@desktop2 ~
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.5.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.5.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --disable-werror --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.5.2 (GCC)

because I could not get
our MinGW machine (the latest download available a month back) configure to
properly generate the H5pubconf.h file (no changes to defines - just copied).
From my searching, it seems to happen often, but I could not find any solution.

Some people seem to have troubles with line-endings.
Just check that the Unix LF line endings in the source files are not being overwritten with Windows endings during the unpacking of the source.
If they *are* being overwritten by Windows line endings then try to configure your Windows 'tar' utility to stop doing that ... or use a different tar utility. I use the one that shipped with my MinGW/MSYS, and it seems fine.
(I don't know if that could be the cause of your problems.)

Worst case, I might need to work with you for testing (send you a private
snapshot) our changes?

No worries with that.
I do have reliable git and svn clients if that makes it easier. Otherwise just send me the snapshot (or a link to it).

Cheers,
Rob

···

----- Original Message ----- From: "Allen D Byrne"