[CDRIVER-607] Compiler warnings on mingw-w64 (gcc) Created: 04/Apr/15  Updated: 03/May/17  Resolved: 16/Feb/17

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: TBD

Type: Improvement Priority: Minor - P4
Reporter: Jeroen Ooms [X] Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 7, gcc 4.6.3 (mingw-w64) from the Rtools: http://cran.r-project.org/bin/windows/Rtools/


Issue Links:
Related
is related to CDRIVER-959 mingw build & test in Evergreen Closed

 Description   

Building on windows 7 with mingw-w64 a few issues come up:

Found the following significant warnings:

  yajl/yajl_gen.c:205:5: warning: too many arguments for format [-Wformat-extra-args]
  bson/bson-error.c:111:4: warning: implicit declaration of function 'strerror_s' [-Wimplicit-function-declaration]
  mongoc/mongoc-socket.c:1131:7: warning: implicit declaration of function 'inet_ntop' [-Wimplicit-function-declaration]
  mongoc/mongoc-ssl.c:224:4: warning: implicit declaration of function 'inet_pton' [-Wimplicit-function-declaration]

Moreover, a linking error that only appears when building for 32bit, it does not appear for x64 (I am already including -lws2_32):

./libmongoc.a(mongoc-socket.o):mongoc-socket.c:(.text+0x1373): undefined reference to `inet_ntop'
./libmongoc.a(mongoc-socket.o):mongoc-socket.c:(.text+0x13b3): undefined reference to `inet_ntop'
./libmongoc.a(mongoc-ssl.o):mongoc-ssl.c:(.text+0x3bc): undefined reference to `inet_pton'
collect2: ld returned 1 exit status

I am currently working around this by shipping my own implementation of inet_ntop and inet_pton from but it would be great if this would be fixed in the library. Some example implementations: http://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found



 Comments   
Comment by A. Jesse Jiryu Davis [ 16/Feb/17 ]

Thanks Jeroen!

Comment by Jeroen Ooms [ 16/Feb/17 ]

It turned out `inet_ntop` is actually missing in older versions of ming-w64 when compiling in 32bit. I ended up bundling my own version with mongolite: https://github.com/jeroenooms/mongolite/blob/master/src/win32/ipv6.c

The other warning is gone because I have switched to compiling with

-D__USE_MINGW_ANSI_STDIO

This makes that mingw use unix type format strings instead of windows ones.

Comment by A. Jesse Jiryu Davis [ 15/Feb/17 ]

Hi Jeroen, I want to check - are these warnings and the inet_ntop linker error still issues for you with the 1.6.0 driver?

Comment by Jeroen Ooms [X] [ 04/Apr/15 ]

A fix for the yajl warning is here: https://github.com/lloyd/yajl/issues/143

Comment by Hannes Magnusson [ 04/Apr/15 ]

In the PHP driver we also have an inet_pton() issue as older PHP versions provide its own inet_pton() compatibility function on Windows which conflicts with whatever header mongoc is including.
I've no idea how to fix that as of yet :/

Comment by Jeroen Ooms [X] [ 04/Apr/15 ]

In addition, I get this warning on x64 when compiling libbson:

bson/bson.c: In function '_bson_as_json_visit_int64':
bson/bson.c:2334:4: warning: format '%i' expects argument of type 'int', but argument 3 has type 'int64_t' [-Wformat]
bson/bson.c: In function '_bson_as_json_visit_date_time':
bson/bson.c:2450:4: warning: format '%i' expects argument of type 'int', but argument 3 has type 'int64_t' [-Wformat]

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