Search code examples
linuxmingwcross-compilingberkeley-db

How to compile Berkeley DB 5.3.28 for MXE cross-compiler?


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 ?


Solution

  • 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