Unable to compile mongoc with msys2 under windows 7

323 views
Skip to first unread message

Faith

unread,
Mar 20, 2019, 7:23:05 PM3/20/19
to mongodb-user
Hi, i am follwing the instructions to install mongocxx as given in this tutorial: http://mongocxx.org/mongocxx-v3/installation/

I have come to the part of installing mongoc, following this tutorial: http://mongoc.org/libmongoc/current/installing.html

I followed all the instructions below: "Building on Windows with MinGW-W64 and MSYS2"


So i installed the x86_64 version of msys2, and installed all the required packages,
In the shell MINGW64 i entered in the file of my mongoc drivers, then enter the command:

CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX="C:/mongo-c-driver"

seems to work giving me this output:


CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.


-- The C compiler identification is ;GNU 8.3.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- No CMAKE_BUILD_TYPE selected, defaulting to RelWithDebInfo
file VERSION_CURRENT contained BUILD_VERSION 1.14.0
-- Using bundled libbson
libbson version (from VERSION_CURRENT file): 1.14.0
-- Check if the system is big endian
-- Searching 16 bit integer
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of unsigned short
-- Check size of unsigned short - done
-- Using unsigned short
-- Check if the system is big endian - little endian
-- Looking for snprintf
-- Looking for snprintf - found
-- Looking for reallocf
-- Looking for reallocf - not found
-- Performing Test BSON_HAVE_TIMESPEC
-- Performing Test BSON_HAVE_TIMESPEC - Success
-- struct timespec found
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Looking for rand_r
-- Looking for rand_r - not found
-- Looking for strings.h
-- Looking for strings.h - found
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Looking for strnlen
-- Looking for strnlen - found
-- Looking for stdbool.h
-- Looking for stdbool.h - found
-- Looking for SYS_gettid
-- Looking for SYS_gettid - not found
-- Looking for syscall
-- Looking for syscall - not found
-- Performing Test HAVE_ATOMIC_32_ADD_AND_FETCH
-- Performing Test HAVE_ATOMIC_32_ADD_AND_FETCH - Success
-- Performing Test HAVE_ATOMIC_64_ADD_AND_FETCH
-- Performing Test HAVE_ATOMIC_64_ADD_AND_FETCH - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
libmongoc version (from VERSION_CURRENT file): 1.14.0
-- Searching for zlib CMake packages
-- Found ZLIB: C:/msys64/mingw64/lib/libz.dll.a (found version "1.2.11")
-- zlib found version "1.2.11"
-- zlib include path "C:/msys64/mingw64/include"
-- zlib libraries "C:/msys64/mingw64/lib/libz.dll.a"
-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Looking for sched_getcpu
-- Looking for sched_getcpu - not found
-- Searching for compression library header snappy-c.h
-- Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/snappy/include for Snappy compression)
-- No ICU library found, SASLPrep disabled for SCRAM-SHA-256 authentication.
-- If ICU is installed in a non-standard directory, define ICU_ROOT as the ICU installation path.
-- Compiling against Secure Channel
-- Compiling against Windows SSPI
-- Configuring done
-- Generating done
-- Build files have been written to: C:/mongo-c-driver-1.14.0


then again following the tutorial typing the command:

 make

And there's the output:


Scanning dependencies of target bson_shared
[ 0%] Building C object src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj
In file included from C:/mongo-c-driver-1.14.0/src/libbson/src/bson/bson.h:23,
from C:/mongo-c-driver-1.14.0/src/libbson/src/bson/bcon.h:26,
from C:/mongo-c-driver-1.14.0/src/libbson/src/bson/bcon.c:24:
C:/mongo-c-driver-1.14.0/src/libbson/src/bson/bson-compat.h:27:2: error: #error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
#error "__USE_MINGW_ANSI_STDIO > 0 is required for correct PRI* macros"
^~~~~
make[2]: *** [src/libbson/CMakeFiles/bson_shared.dir/build.make:63: src/libbson/CMakeFiles/bson_shared.dir/src/bson/bcon.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:219: src/libbson/CMakeFiles/bson_shared.dir/all] Error 2
make: *** [Makefile:152: all] Error 2


I searched for hours but google seems to have no clue what this error mean.
I am using the latest release of mongoc 1.14.0, and the latest version of msys.

I have no more clue how to find a solution, hopefully somebody can help me.
Thanks for you attention.

Faith

unread,
Mar 21, 2019, 6:04:22 PM3/21/19
to mongodb-user
Hi,

I come with some update. I finally managed to build mongoc using Cmake GUI and mingw32-make via  windows cmd.
Here's what i've done:

Downloading the latest release of CMake for windows: https://cmake.org/download/
untar mongoc to C:/mongo-c-driver
Open Cmake
in the field Wheres is the code source: C:/mongo-c-driver
in the field where to build the binaries: C:/mnc
click configure
in the list choosed CodeBlocks - MinGW Makefiles (i suspect MinGW Makefiles to do the same)
click finish
edit the  field CMAKE_INTALL_PREFIX with the value C:/mongoc
click configure
click generate

installed mingw64 in C:/mingw64 to be able to use the compiler via the windows command line
opened cmd
cd C:/mnc
mingw32-make install

compilation went ok.

Then it took me some times but i finally managed to build an exe file using the mongoc librairy, i will come back on this later since it's not the main topic here
Im still curious about the" __USE_MINGW_ANSI_STDIO > 0 is required for correct PRI macro" error tho .... what does it means ?

Anyway my problem now is i dont manage to build mongocxx. Here is what i've done so far:

untar to C:/mongo-cxx-driver

using the msys2 mingw64 shell:

cd mongo-cxx-driver
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=C:/mongocxx . -DCMAKE_PREFIX_PATH=C:/mongoc .

OUTPUT:

-- The CXX compiler identification is GNU 8.3.0
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done

-- The C compiler identification is GNU 8.3.0
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Auto-configuring bsoncxx to use C++17 std library polyfills since C++17 is active and user didn't specify otherwise
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found

-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: C:/mongo-cxx-driver-r3.4.0

then:

make install

goes well until 13%

OUTPUT:

[ 13%] Linking CXX executable test_bson.exe
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x12a2): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types10b_document7type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1487): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1b3f): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_array7type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x1d12): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x235d): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x26c0): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x2ce2): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types7b_int327type_idE'
CMakeFiles/test_bson.dir/objects.a(bson_builder.cpp.obj):bson_builder.cpp:(.text+0x2fed): undefined reference to `__imp__ZN7bsoncxx7v_noabi5types6b_bool7type_idE'
collect2.exe: error: ld returned 1 exit status
make[2]: *** [src/bsoncxx/test/CMakeFiles/test_bson.dir/build.make:207: src/bsoncxx/test/test_bson.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:571: src/bsoncxx/test/CMakeFiles/test_bson.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

I am using windows 7 64 bits by the way i dont know if some information if missing to help me let me know.

Thanks for your attention.


Faith

unread,
Mar 22, 2019, 11:57:07 AM3/22/19
to mongodb-user
Hi, afters hours and hours i managed to find a way to compile mongocxx.

Here's how:

First completing the steps to compile mongoc with mingw32-make under the windows power shell (see previous post).
We gonna need boost, because for some mysterious reasons using the c++17 standard lib lead to error in the compilation.
so download boost: https://www.boost.org/users/download/ and untzip it at C:/boost (no compilation to be done).

So now we assume mongoc is now installed in C:/mongoc
and boost at C:/boost

-Download last release of mongocxx
-untar/unzip at C:/mongo-cxx-driver
-open cmake
-in the field where is the source code "C:/mongo-cxx-driver "
-in the field where to build the binaries: "C:/mongocxx"
-click configure
-choose MingGW Makefiles in the list
-choose use default native compiler
-click finish

some error will be announced, dont worry click ok.
Now some Name/Value appear in red.
Find the entry with the name BSONCXX_POLY_USE_BOOST and put the value on true (check the checkbox)
If you want to change the installation directory of mongocxx find the entry named CMAKE_INSTALL_PREFIX and change it to whatever please you.

we gonna add some cache entry to inform where mongoc is and where boost is
-click add Entry and fill the field as follow:

name: CMAKE_PREFIX_PATH
type: PATH
Value: C:/mongoc (or whatever is your mongoc directory installation)
-click ok

-click add entry and fill:
name : BOOST_ROOT
type: PATH
Value C:/boost (or whatever is your boost directory installation)

-Click configure

Some new entries in red may appear, that's normal, click configure again. Then click configure until you got no more red entries.
At this point you should have no error and the gui should indicate Configuring done.

-Click generate
You are done with cmake now we just have to compile under the windows power shell, so for the next step you need mingw64 to be installed on the root of your C drive.
(Or if you have any better solution to use mingw under windows power shell go for it)

-Open cmd (start, search cmd, press enter)
cd C:/mongocxx (or whatever path file for the binaries you choosed in cmake)
mingw32-make install

At this point compilation should be running fine.
Hopefully this might help somebody else.


Reply all
Reply to author
Forward
0 new messages