bmatsuo / lmdb-go

Bindings for the LMDB C library
BSD 3-Clause "New" or "Revised" License
159 stars 58 forks source link

Windows compilation error #91

Closed slav closed 7 years ago

slav commented 7 years ago

When trying to build on windows getting the following error. Any suggestion on how to fix?

.\mdb.c:4625:13: warning: implicit declaration of function 'pthread_mutexattr_setrobust' [-Wimplicit-function-declaration]
    || (rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST))
             ^
.\mdb.c:4625:49: error: 'PTHREAD_MUTEX_ROBUST' undeclared (first use in this function)
    || (rc = pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST))
                                                 ^
.\mdb.c:4625:49: note: each undeclared identifier is reported only once for each function it appears in
.\mdb.c: In function 'mdb_mutex_failed':
.\mdb.c:351:37: warning: implicit declaration of function 'pthread_mutex_consistent' [-Wimplicit-function-declaration]
 #define mdb_mutex_consistent(mutex) pthread_mutex_consistent(mutex)
                                     ^
.\mdb.c:10002:10: note: in expansion of macro 'mdb_mutex_consistent'
    rc2 = mdb_mutex_consistent(mutex);
          ^

The main issue is that PTHREAD_MUTEX_ROBUST is undefined.

bmatsuo commented 7 years ago

Interesting. This may be considered a bug in lmdb itself, as the presence of Windows should be detected, and the library tries to select available APIs by default. So it may be worth bringing up on the official mailing list.

Can you tell me any more about your build environment? Are you compiling inside cygwin. It has been a while since I got everything building on Windows.

I haven't found any info in the official openldap-technical mailing list. But I found the following in the mdb.c source file.

/** Some platforms define the EOWNERDEAD error code
 * even though they don't support Robust Mutexes.
 * Compile with -DMDB_USE_ROBUST=0, or use some other
 * mechanism like -DMDB_USE_SYSV_SEM instead of
 * -DMDB_USE_POSIX_MUTEX. (SysV semaphores are
 * also Robust, but some systems don't support them
 * either.)
 */

I doubt that MDB_USE_SYSV_SEM is supported on Windows. But MDB_USE_POSIX_MUTEX may work. If all else fails I think defining MDB_USE_ROBUST=0 will work.

I have pushed a branch, bmatsuo/issues/91/windows-robust-sem, which defines MDB_USE_POSIX_MUTEX. Can you test it out and let me know if the package builds and the tests pass?

Also, please do let me know what your environment is like. I had a previous issue getting compilation to work on Windows. I'm not sure if that was after robust mutex support was added or not.

slav commented 7 years ago

Yes, trying to build under cygwin. Do you need any other info? I'll try the other branch and will let you know.

Is this file straight out of LMDB? Or have you modified it in some way for go?

bmatsuo commented 7 years ago

Thanks for the info. I presume you have a 64-bit processor as well, though I doubt architecture is significant.

I have not modified the C source. If you try to compile the LMDB project I think you will run into the same errors.

I noticed in my previous comment that the branch name looked strange because of GitHub markup. The name is bmatsuo/issues/91/windows-robust-sem, if there was any confusion. Thanks. Let me know how it goes.

slav commented 7 years ago

I'm getting can't load package: package github.com/bmatsuo/lmdb-go/lmdb: D:\Projects\Go\src\github.com\bmatsuo\lmdb-go\lmdb\lmdb.go: invalid #cgo line: #cgo windows -DMDB_USE_POSIX_MUTEX

slav commented 7 years ago

Fixing flags to #cgo windows CFLAGS: -DMDB_USE_POSIX_MUTEX results in the same build error with PTHREAD_MUTEX_ROBUST not found

slav commented 7 years ago

Although #cgo windows CFLAGS: -DMDB_USE_ROBUST=0 seems to have fixed that part, running into other issues:

D:\Projects\Go\src\github.com\bmatsuo\lmdb-go\lmdb>go build
# github.com/bmatsuo/lmdb-go/lmdb
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lmingw32
collect2: error: ld returned 1 exit status
slav commented 7 years ago

I ended up installing http://tdm-gcc.tdragon.net/ instead of cygwin and everything builds there.

slav commented 7 years ago

Interestingly enough, master branch builds with tdm-gcc too. I guess something is missing in cygwin compiler. The windows flag is not needed. Need right compiler.

bmatsuo commented 7 years ago

That is very interesting. Thanks for your investigation. Sorry about the bad cgo directive (on my branch). But I'm glad you worked past it.

I did have things compiling under cygwin originally. I wonder why that is no longer working.