2

Has anybody a solution for building Berkeley DB for MXE's cross-compile environment?

When I run my build script:

 #!/bin/bash

 MXE_PATH=/path/to/mxe
 
 db=db-5.3.28

 rm -rf ./$db/build_mxe
 mkdir -p ./$db/build_mxe
 cd ./$db/build_mxe
 
 sed -i "s/WinIoCtl.h/winioctl.h/g" ../src/dbinc/win_db.h

 CC=$MXE_PATH/usr/bin/i686-w64-mingw32.static-gcc \
 CXX=$MXE_PATH/usr/bin/i686-w64-mingw32.static-g++ \

 ../dist/configure \
     --build=x86_64-pc-linux-gnu \
     --host=x86 \
     --disable-replication \
     --enable-cxx \
     --enable-mingw \
     --prefix=/path/to/dev/mingw_db

  make -j6; make -j6 install

The compiler warns of direct.h missing:

../src/dbinc/win_db.h:21:20: fatal error: direct.h: No such file or directory compilation terminated.

direct.h and all dependent files exist in mxe/usr/i686-w64-mingw32.static/include directory

So how to force the compiler to use these files ?

Demon
  • 139
  • 5

2 Answers2

0

The MXE developers have slowly improved the build process for MXE's deps. Berkeley DB is now easy to compile the version you need using make db within the MXE source, and if a specific version is needed, you can change it in src/db.mk. and again run make db will update the files accordingly.

There is one error during the make process in which libtool doesn't find the db binaries properly due to a current db patch (src/db-2-install-exe.patch) in MXE that's applied during compiling db which will be deprecated. However, in the meantime the fix is to delete the db patch file and add the following flag in src/db.mk with the other configure options after (MXE_CONFIGURE_OPTS):

--program-transform-name='s,.exe,,;s,\(.*\),\1.exe,' \

This is much simpler and keeps the MXE source cleaner/manageable than using a custom compile script for BDB.

Demon
  • 139
  • 5
  • I am trying to fix the db build on mxe; I tried this but it's not working; I'm looking at the temp build tree and I can't see any differences from before (and same errors not being able to find the files because they all have the .exe extension) – Gregorio Litenstein Jun 28 '20 at 05:36
  • Make sure your build tree is clean. Possibly reclone the mxe github. I haven't been at this for a bit. They may have updated their compile process since then. I'm not up to par with the procedure if it has changed. Check https://mxe.cc and https://github.com/mxe. Also refer to https://bitcointalk.org/index.php?topic=1080289.0 for some guidance. – Demon Jun 28 '20 at 11:56
  • I just attempted a basic mxe setup, compiling mxe with `make cc` then building db with `make db` and there was no issue. It did compile with db v6.1.26. I then switched it over to version 5.3.28 and also compiled without error. – Demon Jun 28 '20 at 13:40
  • I'm using gcc8 and trying to update it to the latest stable (6.1.26, which is what is on master gave me the same issue, though) – Gregorio Litenstein Jul 01 '20 at 18:59
  • @GregorioLitenstein Could please post the log file that results from the compiling error for gcc and db (separately) on https://pastebin.com/ . I just got an error myself when using mxe's update script (`make update-package-gcc` (gc also) then `make gcc`) to to check/update gcc which it downloaded version 10.1.0 and 8.0.4 for gc. If we end up having the same errors, then you should file a new issue on mxe's github. – Demon Jul 02 '20 at 00:03
  • @GregorioLitenstein The log file should be located in the path (example) >> /path/to/mxe/log/gcc_i686-w64-mingw32.static – Demon Jul 02 '20 at 00:20
  • It's not going to be the same because I have no issue building gcc. And my db builds are failing due to unexpected `.exe` extension on generated files; and for some reason it appears the `--program-transform-name` argument is not working. – Gregorio Litenstein Jul 04 '20 at 06:52
  • @GregorioLitenstein can you DM me on discord demon#9191 ? – Demon Jul 04 '20 at 10:16
0

I've improved upon my build script and solved my question:

I had to fix the original script which then perfected the build.

The correct syntax goes as follows:

#!/bin/bash

## Path to MXE source
 MXE_PATH=/home/demon/dev/mxe
## Path for mingw headers
 MXE_INCLUDE=$MXE_PATH/usr/i686-w64-mingw32.static/include

## Path to db source
 db=db-6.1.26

## Make a clean working tree and Create working DIR 
## You can also use `make distclean` within build_mxe to start fresh
 
 rm -rf ./$db/build_mxe
 mkdir -p ./$db/build_mxe

## Enter working directory
 cd ./$db/build_mxe

## Correct naming of header file
 sed -i "s/WinIoCtl.h/winioctl.h/g" ../src/dbinc/win_db.h


## Define CC and C++ compiler & user level commands
export CC=$MXE_PATH/usr/bin/i686-w64-mingw32.static-gcc
export CXX=$MXE_PATH/usr/bin/i686-w64-mingw32.static-g++
export AR=$MXE_PATH/usr/bin/i686-w64-mingw32.static-ar
export STRIP=$MXE_PATH/usr/bin/i686-w64-mingw32.static-strip
export RANLIB=$MXE_PATH/usr/bin/i686-w64-mingw32.static-ranlib

### Find mingw headers in non-standard directory
export CPPFLAGS=-I$MXE_INCLUDE


## Configure the build
 ../dist/configure \
     --build=x86_64-pc-linux-gnu \
     --host=x86 \
     --disable-replication \
     --enable-cxx \
     --enable-mingw \
     --program-transform-name='s,.exe,,;s,\(.*\),\1.exe,' \
     --prefix=/home/demon/dev/mxe_db \
     --exec-prefix=/home/demon/dev/mxe_db

## Build DB and install it
 make -j(nproc); make -j(nproc) install

The corrected issues:

  • Set the environment variable to locate mingw headers using the CPPFLAGS variable
  • Set correct compiler commands and user commands for CC, CXX, AR, STRIP, and RANLIB environment variables to MXE's compiler with export <variable>

That did the trick !

You can follow the complete build here:

https://pastebin.com/aP5rWQSC

Contents of the output (--prefix) directory's finished build: Build output (--prefix) directory

Demon
  • 139
  • 5