[CDRIVER-2447] Update install instructions for MSYS2 Created: 04/Jan/18  Updated: 28/Oct/23  Resolved: 29/Jan/18

Status: Closed
Project: C Driver
Component/s: docs, libmongoc
Affects Version/s: 1.9.0
Fix Version/s: 1.10.0

Type: Improvement Priority: Major - P3
Reporter: mithril Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:
  • windows 7x64
  • msys2 mingw32 mingw64

Attachments: Text File CMakeOutput.log     File mongoc-config.h    
Issue Links:
Related

 Description   

I test with mingw32 and mingw64

1.9.0 release got this error:

  CC       tests/test_libmongoc-test-mongoc-usleep.o
  CC       tests/test_libmongoc-test-mongoc-util.o
  CC       tests/test_libmongoc-test-mongoc-version.o
  CC       tests/test_libmongoc-test-mongoc-write-commands.o
  CC       tests/test_libmongoc-test-mongoc-write-concern.o
  CC       tests/test_libmongoc-TestSuite.o
  CC       tests/test_libmongoc-test-mongoc-x509.o
  CC       tests/test_libmongoc-test-mongoc-stream-tls.o
  CC       tests/test_libmongoc-test-mongoc-stream-tls-error.o
  CC       tests/test_libmongoc-ssl-test.o
  CC       tests/test_libmongoc-test-mongoc-cyrus.o
  CCLD     test-libmongoc.exe
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0xc8): undefined reference to `__ns_initparse'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0xc8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__ns_initparse'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0x108): undefined reference to `__ns_parserr'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0x108): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__ns_parserr'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:2715: test-libmongoc.exe] Error 1
make[1]: Leaving directory '/e/Project/allproject_git/test/mongo-c-driver-1.9.0'
make: *** [Makefile:5167: all-recursive] Error 1

PS:
There are a log of warnings about `_mongoc_get_cpu_count` while compliing:

  ^~~~~~~
  CC       src/mongoc/libmongoc_la-mongoc-stream-tls-openssl-bio.lo
In file included from src/mongoc/mongoc-stream-tls-openssl-bio.c:26:0:
src/mongoc/mongoc-counters-private.h: In function ‘_mongoc_get_cpu_count’:
src/mongoc/mongoc-counters-private.h:85:2: warning: #warning "_mongoc_get_cpu_count() not supported, defaulting to 1." [-Wcpp]
 #warning "_mongoc_get_cpu_count() not supported, defaulting to 1."
  ^~~~~~~



 Comments   
Comment by Githook User [ 29/Jan/18 ]

Author:

{'email': 'jesse@mongodb.com', 'name': 'A. Jesse Jiryu Davis', 'username': 'ajdavis'}

Message: CDRIVER-2447 MSYS2 install instructions
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/537b5364c737b80b2d9f600967645aec7d4583d6

Comment by mithril [ 06/Jan/18 ]

1. remove `msys/usr/bin` in windows environment
2. install `mingw64/mingw-w64-x86_64-cyrus-sasl` (I had msys/libsasl-devel and msys/libsasl installed, which result make find)

Then succeeded.

I think full steps should be add to http://mongoc.org/libmongoc/current/installing.html#building-from-a-release-tarball

pacman --noconfirm -Syu
pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-extra-cmake-modules make tar 
pacman --noconfirm -S mingw64/mingw-w64-x86_64-cyrus-sasl
 
 
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.9.0/mongo-c-driver-1.9.0.tar.gz
tar -xzf mongo-c-driver-1.9.0.tar.gz
cd mongo-c-driver-1.9.0
cd src/libbson
 
CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/libbson"
 
make install
 
cd ../..
 
CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/libbson"
 
make

Comment by mithril [ 06/Jan/18 ]

It looks like make found wrong path ?? `D:/msys64/usr/lib/`
But I did start with ming64.bat .

Comment by mithril [ 06/Jan/18 ]

I think you miss `cd ../..` before

 
CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/libbson"
 
make

And make got another different error:

$ make
Current version (from VERSION_CURRENT file): 1.9.0
-- Searching for libbson CMake packages
--   libbson found version "1.9.0"
--   libbson include path "C:/Program Files (x86)/libbson/include/libbson-1.0"
--   libbson libraries "C:/Program Files (x86)/libbson/lib/libbson-1.0.dll.a"
--   libbson-static found version "1.9.0"
--   libbson-static include path "C:/Program Files (x86)/libbson/include/libbson-1.0"
--   libbson-static libraries "C:/Program Files (x86)/libbson/lib/libbson-static-1.0.a-lmingw32;-lgcc;-lmoldname;-lmingwex;-lpthread;-ladvapi32;-lshell32;-luser32;-lkernel32;-lmingw32;-lgcc;-lmoldname;-lmingwex;D:/msys64/usr/lib/librt.a;D:/msys64/usr/lib/libm.a;ws2_32"
-- Searching for sasl/sasl.h
--   Found in D:/msys64/usr/include
-- Searching for libsasl2
--   Found D:/msys64/usr/lib/libsasl2.dll.a
-- Searching for compression library header snappy-c.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=C:/path/to/snappy/include for Snappy compression)
-- Enabling zlib compression (bundled)
-- Compiling against OpenSSL
-- Compiling against Cyrus SASL
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Workspace/allproject_git/mongo-c-driver-1.9.0
[  0%] Building C object CMakeFiles/mongoc_shared.dir/src/zlib-1.2.11/adler32.c.obj
In file included from D:/msys64/usr/include/sys/select.h:26:0,
                 from D:/msys64/usr/include/sys/types.h:68,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zconf.h:444,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zlib.h:34,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zutil.h:22,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/adler32.c:8:
D:/msys64/usr/include/sys/_timeval.h:40:18: error: conflicting types for 'time_t'
 typedef _TIME_T_ time_t;
                  ^~~~~~
In file included from D:/msys64/mingw64/x86_64-w64-mingw32/include/stddef.h:7:0,
                 from D:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/7.2.0/include/stddef.h:1,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zconf.h:247,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zlib.h:34,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/zutil.h:22,
                 from E:/Workspace/allproject_git/mongo-c-driver-1.9.0/src/zlib-1.2.11/adler32.c:8:
D:/msys64/mingw64/x86_64-w64-mingw32/include/crtdefs.h:138:20: note: previous declaration of 'time_t' was here
 typedef __time64_t time_t;
                    ^~~~~~
make[2]: *** [CMakeFiles/mongoc_shared.dir/build.make:63: CMakeFiles/mongoc_shared.dir/src/zlib-1.2.11/adler32.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:586: CMakeFiles/mongoc_shared.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

Comment by A. Jesse Jiryu Davis [ 06/Jan/18 ]

Oh, sorry, I missed one line in my previous example, but I've added it now. Please see my previous comment. I use cmake, not ./configure. I've never gotten ./configure to work in MSYS2 so I only use cmake. If you follow the steps I pasted above I expect you will be able to compile the driver with MSYS2 and cmake.

Comment by mithril [ 06/Jan/18 ]

What is the option you pass to ./configure ? Not show in your example.
Would you please paste the whole steps?

I found `./configure` under `mongo-c-driver-1.9.0\src` and `mongo-c-driver-1.9.0\src\libbson` , the result is different.

Comment by A. Jesse Jiryu Davis [ 06/Jan/18 ]

Yes, and "make install" then installs libbson in system paths. I have then successfully compiled libmongoc using MSYS2.

Comment by mithril [ 06/Jan/18 ]

This line

cd src/libbson

You only compiled libbson, libbson is fine I have said in previous comment . The problem is libmongoc can't be compiled.

Comment by A. Jesse Jiryu Davis [ 05/Jan/18 ]

Here are steps that worked for me:

Install MSYS2 from msys2.github.io, the x86_64 version (not i686)

Open c:\msys64\ming64_shell.bat (not the msys2_shell!)

pacman --noconfirm -Syu

Pacman told me to close and reopen shell and do it again:

pacman --noconfirm -Syu
pacman --noconfirm -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake mingw-w64-x86_64-extra-cmake-modules make tar
wget https://github.com/mongodb/mongo-c-driver/releases/download/1.9.0/mongo-c-driver-1.9.0.tar.gz
tar -xzf mongo-c-driver-1.9.0.tar.gz
cd mongo-c-driver-1.9.0
cd src/libbson
 
CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/libbson"
 
make install
 
CC=/mingw64/bin/gcc.exe /mingw64/bin/cmake -G "MSYS Makefiles" -DCMAKE_PREFIX_PATH="C:/Program Files (x86)/libbson"
 
make

Comment by mithril [ 05/Jan/18 ]

I have tried two way (both can compile libbson successfully, but libmongoc not)

1. build from release

followed this section http://mongoc.org/libmongoc/current/installing.html#building-from-a-release-tarball

launch mingw32 shell( http://www.msys2.org/ ) then,

$ wget https://github.com/mongodb/mongo-c-driver/releases/download/1.9.0/mongo-c-driver-1.9.0.tar.gz
$ tar xzf mongo-c-driver-1.9.0.tar.gz
$ cd mongo-c-driver-1.9.0
$ ./configure --disable-automatic-init-and-cleanup

`./configure` succeeded. But `make` got

  CCLD     test-libmongoc.exe
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0xc8): undefined reference to `__ns_initparse'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0xc8): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__ns_initparse'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0x108): undefined reference to `__ns_parserr'
./.libs/libmongoc.a(libmongoc_la-mongoc-client.o):mongoc-client.c:(.text+0x108): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__ns_parserr'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:2715: test-libmongoc.exe] Error 1
make[1]: Leaving directory '/e/Project/allproject_git/test/mongo-c-driver-1.9.0'
make: *** [Makefile:5167: all-recursive] Error 1

2. Build using windows cmd run cmake

Use source code https://github.com/mongodb/mongo-c-driver/

Alter this script
https://github.com/mongodb/mongo-c-driver/blob/master/.evergreen/compile-windows-mingw.bat

to

rem Ensure Cygwin executables like sh.exe are not in PATH
set PATH=C:\Windows\system32;C:\Windows;E:\msys64\mingw32\bin\;C:\mongoc;src\libbson
 
echo CONFIGURE_FLAGS %CONFIGURE_FLAGS%
 
 
set INSTALL_DIR=C:\mongoc
 
 
set CMAKE=E:\msys64\mingw32\bin\cmake.exe
set CMAKE_MAKE_PROGRAM=E:\msys64\mingw32\bin\mingw32-make.exe
set CC=E:\msys64\mingw32\bin\gcc.exe
 
cd src\libbson
%CMAKE% -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=%CMAKE_MAKE_PROGRAM% -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_BUILD_TYPE="Release" %CONFIGURE_FLAGS%
 
%CMAKE_MAKE_PROGRAM%
%CMAKE_MAKE_PROGRAM% install
 
cd ..\..
%CMAKE% -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=%CMAKE_MAKE_PROGRAM% -DCMAKE_C_FLAGS="-std=c99 -pedantic" -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% -DCMAKE_BUILD_TYPE="Release" %CONFIGURE_FLAGS%
 
%CMAKE_MAKE_PROGRAM%
%CMAKE_MAKE_PROGRAM% install
 
set MONGOC_TEST_SKIP_LIVE=on
test-libmongoc.exe --no-fork -d -F test-results.json

it build `libbson-1.0` successfully

But failed with libmongoc :

E:\Project\allproject_git\test\mongo-c-driver-master\mongo-c-driver-master>E:\msys64\mingw32\bin\cma
ke.exe -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=E:\msys64\mingw32\bin\mingw32-make.exe -DCMAKE_C_FL
AGS="-std=c99 -pedantic" -DCMAKE_INSTALL_PREFIX=C:\mongoc -DCMAKE_PREFIX_PATH=C:\mongoc -DCMAKE_BUIL
D_TYPE="Release"
Current version (from VERSION_CURRENT file): 1.10.0-dev
Previous release (from VERSION_RELEASED file): 1.9.0
-- Searching for libbson CMake packages
CMake Error at CMakeLists.txt:9 (_message):
  File or directory
  E:/Project/allproject_git/test/mongo-c-driver-master/include/libbson-1.0
  referenced by variable BSON_INCLUDE_DIRS does not exist !
Call Stack (most recent call first):
  src/libbson/libbson-1.0-config.cmake:28 (message)
  src/libbson/libbson-1.0-config.cmake:32 (set_and_check)
  CMakeLists.txt:61 (find_package)

Set `BSON_INCLUDE_DIRS ` in `compile-windows-mingw.bat` , not work .
Copy `include/libbson-1.0` to `E:/Project/allproject_git/test/mongo-c-driver-master/include/libbson-1.0` , got

E:\Project\allproject_git\test\mongo-c-driver-master\mongo-c-driver-master>E:\msys64\mingw32\bin\cma
ke.exe -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=E:\msys64\mingw32\bin\mingw32-make.exe -DCMAKE_C_FL
AGS="-std=c99 -pedantic" -DCMAKE_INSTALL_PREFIX=C:\mongoc -DCMAKE_PREFIX_PATH=C:\mongoc -DCMAKE_BUIL
D_TYPE="Release"
Current version (from VERSION_CURRENT file): 1.10.0-dev
Previous release (from VERSION_RELEASED file): 1.9.0
-- Searching for libbson CMake packages
--   libbson found version "1.10.0-dev"
--   libbson include path "E:/Project/allproject_git/test/mongo-c-driver-master/include/libbson-1.0"
 
--   libbson libraries "BSON_LIBRARY-NOTFOUND"
--   libbson-static found version "1.10.0-dev"
--   libbson-static include path "E:/Project/allproject_git/test/mongo-c-driver-master/include/libbs
on-1.0"
--   libbson-static libraries "BSON_STATIC_LIBRARY-NOTFOUND-lmingw32;-lgcc;-lmoldname;-lmingwex;-lpt
hread;-ladvapi32;-lshell32;-luser32;-lkernel32;-lmingw32;-lgcc;-lmoldname;-lmingwex;ws2_32"
CMake Error at CMakeLists.txt:9 (_message):
  ENABLE_TESTS requires ENABLE_STATIC
Call Stack (most recent call first):
  CMakeLists.txt:91 (message)
 
 
-- Configuring incomplete, errors occurred!
See also "E:/Project/allproject_git/test/mongo-c-driver-master/mongo-c-driver-master/CMakeFiles/CMak
eOutput.log".

log file uploaded.

PS: I don't know much about compiling c lib, only know ./configure, make command ...
I found `mongoc-config.h` under `mongo-c-driver-1.9.0\src\mongoc` , is it ? Last time I tried to make by mingw64 with some flag.

Comment by A. Jesse Jiryu Davis [ 04/Jan/18 ]

Hi, could you tell me more about how you're compiling the driver, please? Do you use cmake or the Autotools? Could you attach a copy of the generated mongoc-config.h?

Generated at Wed Feb 07 21:15:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.