Problems compiling with Visual Studio 2015

487 views
Skip to first unread message

Jeff McKenna

unread,
Apr 15, 2016, 10:52:01 AM4/15/16
to spatiali...@googlegroups.com
Hello everyone,

I am trying to compile version 4.4.0-RC0 with Visual Studio 2015 on
Windows. The compile seems to break at the file gg_extras.c on line#65:

****
cl /nologo -I.\src\headers -I.
-ID:\build\libiconv\source\include -ID:\build\geos-04042016\include
-ID:\build\geos-04042016\capi -ID:\build\freexl-1.0.2\src
-ID:\build\freexl-1.0.2\headers -ID:\build\sqlite-3.12.0\build
-ID:\build\zlib-1.2.8 -ID:\build\libxml2-2.9.3\include
-ID:\build\proj-4.9.2\src /nologo /Ox /fp:precise /W3 /MD
/D_CRT_SECURE_NO_WARNINGS /DDLL_EXPORT /DYY_NO_UNISTD_H /c
src\gaiageo\gg_extras.c /Fosrc\gaiageo\gg_extras.obj
gg_extras.c
src\gaiageo\gg_extras.c(65): error C2491: 'rint': definition of
dllimport function not allowed
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
Studio 14.0\VC\BIN\cl.EXE"' : return code '0x2'
Stop.
****

Some background information for you, before you respond with "please use
MinGW" ha:

I distribute libspatialite in MS4W (http://ms4w.com) for the MapServer
community (roughly 5,000 downloads per month in fact, and increasing).
All libraries for MS4W are compiled from source (over 160, including
Apache & its modules, PHP & its extensions). I've recently transitioned
from a very old Visual Studio 2008 compiler, to Visual Studio 2015, for
the entire MS4W build environment.

I should note that with the 2008 environment libspatialite compiled
successfully; however the 2015 compiler throws that error.

Short story: can anyone see what I'm missing, to compile 4.4.0-RC0 with
Visual Studio 2015?

Thanks,

-jeff

--
Jeff McKenna
MapServer Consulting and Training Services
http://www.gatewaygeomatics.com/








Jeff McKenna

unread,
Apr 15, 2016, 12:25:54 PM4/15/16
to spatiali...@googlegroups.com
An update:

I noticed that libspatialite's nmake.opt sets a warning level of "/W3",
and since GDAL, MapServer use "/W4" I changed to that; that helped me
get more details on the error:

src\gaiageo\gg_extras.c(65): warning C4211: nonstandard extension
used: redefined extern to static

I therefore modified gg_extras.ca line 65 to contain:

extern double

Now the compile proceeds as far as the linker, and has 3 missing symbols:

****
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library spatialite_i.lib and object spatialite_i.exp
gg_utf8.obj : error LNK2019: unresolved external symbol _locale_charset
referenced in function _gaiaGetLocaleCharset
spatialite.obj : error LNK2019: unresolved external symbol
_virtual_knn_extension_init referenced in function
_init_spatialite_virtualtables
spatialite.obj : error LNK2019: unresolved external symbol _gaiaCutter
referenced in function _fnct_Cutter
spatialite.dll : fatal error LNK1120: 3 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
Studio 14.0\VC\BIN\link.EXE"' : return code '0x460'
Stop.
****

Diving into that now

Hopefully someday my steps in this mailing list archive help someone else.

-jeff



--
Jeff McKenna
MapServer Consulting and Training Services
http://www.gatewaygeomatics.com/




a.fu...@lqt.it

unread,
Apr 15, 2016, 4:47:00 PM4/15/16
to spatiali...@googlegroups.com
On Fri, 15 Apr 2016 11:51:57 -0300, Jeff McKenna wrote:
> Some background information for you, before you respond with "please
> use MinGW" ha:
>
> I distribute libspatialite in MS4W (http://ms4w.com) for the
> MapServer community (roughly 5,000 downloads per month in fact, and
> increasing).
>

Hi Jeff,

you are too famous to require any self-introduction, your reputation
precedes you.

> gg_extras.c
> src\gaiageo\gg_extras.c(65): error C2491: 'rint': definition of
> dllimport function not allowed
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
> Studio 14.0\VC\BIN\cl.EXE"' : return code '0x2'
> Stop.
>

few useful references:
https://msdn.microsoft.com/en-us/library/dn465165.aspx
https://en.wikipedia.org/wiki/C99

short summary: in the remote 1999 the ISO/IEC 9899:1999
international standard (aka C99) introduced several further
canonic functions expected to be supported by any C compiler,
one of them being rint()

gcc (and consequently MinGW) immediately supported the new
C99 requirements.
Microsoft MSVC was a little bit lazier, and started supporting
C99 only since 2013 and 2015 editions (of course, better late
than never).


> I should note that with the 2008 environment libspatialite compiled
> successfully; however the 2015 compiler throws that error.
>

As we have already seen, any MSVC edition released before
2013 surely lacked a native implementation of rint(), so the
only viable workaround was passing an internal implementation
of rint() when using the MSVC compiler.
It correctly worked on previous versions of MSVC, but it now
fails on 2013 and 2015 editions because the internal rint()
will now conflict with the native MSVC rint().

quick-and-dirty fix:
--------------------
just completely remove the internal rint() implementation
from the gg_extra.c source when using MSVC 2013 or 2015

more sophisticated solution:
----------------------------
after the more recent MSVC/C99 evolutions it's now obvious
the the conditional macro in gg_extra.c sucks:

#if defined(_WIN32) && !defined(__MINGW32__)

testing for a Windows platform and NOT MinGW is too much
simplistic: we are certainly required to perform a deeper
macro test so to correctly discriminate between MSVC-pre-2013
and MSVC-post-2013.
Any possible useful suggestion is warmly welcome and will
be quickly incorporated into the codebase.

bye Sandro

Even Rouault

unread,
Apr 15, 2016, 4:52:04 PM4/15/16
to spatiali...@googlegroups.com, a.fu...@lqt.it
To detect MSVC >= VS 2013, you can likely use :

#if defined (_MSC_VER) && _MSC_VER >= 1800

> Any possible useful suggestion is warmly welcome and will
> be quickly incorporated into the codebase.
>
> bye Sandro

--
Spatialys - Geospatial professional services
http://www.spatialys.com

Jeff McKenna

unread,
Apr 15, 2016, 5:11:01 PM4/15/16
to spatiali...@googlegroups.com
Hi Sandro, Even, all,

Here are some more changes that I've made to get the 4.4.0-RC0 compile
further along (you can definitely class these changes as "quick and
dirty" ha) Let me know if they can be improved :


- in makefile.vc add the missing objects to LIBOBJ, as:

src\spatialite\virtualknn.obj src\cutter\gaia_cutter.obj

- handle strcasecmp use by adding the following to the files
"virtualknn.c" and "gaia_cutter.c":

#if defined(_WIN32) && !defined(__MINGW32__)
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#endif

- handle pid_t use by adding the following to "gaia_cutter.c":

#if defined(_WIN32) && !defined(__MINGW32__)
#define pid_t int
#endif

Which leaves me with one last issue:

****
Creating library spatialite_i.lib and object spatialite_i.exp
gg_utf8.obj : error LNK2019: unresolved external symbol _locale_charset
referenced in function _gaiaGetLocaleCharset
spatialite.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
Studio 14.0\VC\BIN\link.EXE"' : return code '0x460'
Stop.
****

We're almost there :)

-jeff


a.fu...@lqt.it

unread,
Apr 15, 2016, 5:21:10 PM4/15/16
to spatiali...@googlegroups.com
On Fri, 15 Apr 2016 13:25:50 -0300, Jeff McKenna wrote:
> Creating library spatialite_i.lib and object spatialite_i.exp
> gg_utf8.obj : error LNK2019: unresolved external symbol
> _locale_charset referenced in function _gaiaGetLocaleCharset
> spatialite.obj : error LNK2019: unresolved external symbol
> _virtual_knn_extension_init referenced in function
> _init_spatialite_virtualtables
> spatialite.obj : error LNK2019: unresolved external symbol
> _gaiaCutter referenced in function _fnct_Cutter
> spatialite.dll : fatal error LNK1120: 3 unresolved externals
>

Hi Jeff,

please note: testing and eventually updating the makefile.vc
supporting MSVC usually is the very last step before releasing
any new "stable" version, but it's usually ignored for all
interim release candidates.

both VirtualKNN and GaiaCutter are new 4.4.0 additions: a
possible quick fix could possibly to manually add into the
makefile.vc the following two object files:

src\cutter\gaia_cutter.obj
src\spatialite\virtualknn.obj

I've no idea about the missing symbol "_locale_charset";
it's usually expected to be defined into libiconv.dll

bye Sandro

a.fu...@lqt.it

unread,
Apr 15, 2016, 5:40:44 PM4/15/16
to spatiali...@googlegroups.com
On Fri, 15 Apr 2016 18:10:58 -0300, Jeff McKenna wrote:
> Hi Sandro, Even, all,
>
> Here are some more changes that I've made to get the 4.4.0-RC0
> compile further along (you can definitely class these changes as
> "quick and dirty" ha) Let me know if they can be improved :
>
>
> - in makefile.vc add the missing objects to LIBOBJ, as:
>
> src\spatialite\virtualknn.obj src\cutter\gaia_cutter.obj
>

ok: see my previos mail


> - handle strcasecmp use by adding the following to the files
> "virtualknn.c" and "gaia_cutter.c":
>
> #if defined(_WIN32) && !defined(__MINGW32__)
> #define strcasecmp _stricmp
> #define strncasecmp _strnicmp
> #endif
>
> - handle pid_t use by adding the following to "gaia_cutter.c":
>
> #if defined(_WIN32) && !defined(__MINGW32__)
> #define pid_t int
> #endif
>

both conditionals seem to be valid


> Which leaves me with one last issue:
>
> ****
> Creating library spatialite_i.lib and object spatialite_i.exp
> gg_utf8.obj : error LNK2019: unresolved external symbol
> _locale_charset referenced in function _gaiaGetLocaleCharset
> spatialite.dll : fatal error LNK1120: 1 unresolved externals
> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual
> Studio 14.0\VC\BIN\link.EXE"' : return code '0x460'
> Stop.
> ****
>

as I've prevously said, this symbol is expected to be declared
by iconv.lib (from the standard OSGeo4W distro)
It correctly worked before, and I can ensure you that this
specific part of spatialite never changed since 2012.
may be you are using some different (non OSGeo4W) iconv ?

bye Sandro

Jeff McKenna

unread,
Apr 15, 2016, 5:54:35 PM4/15/16
to spatiali...@googlegroups.com
My reasoning for explaining at the beginning (MS4W, all the libraries
compiled, etc) was to avoid anyone asking me to use other libraries :)
Such as of course OSGeo4W. You are correct, I am using non-OSGeo4W
Iconv. I was trying to explain that in my beginning e-mail here, that
MS4W does not use any externally compiled libraries. None at all. Not
for Apache, PHP, GDAL, MapServer, or any libraries. :) This also means
iconv. :)

I compiled inconv-1.14 from source. It seems to work fine for other
software projects, I am not sure why I can't use this iconv for
libspatialite.

I'll keep digging. Hmmmmm tricky.... It sounds like it is a problem on
my side, so I will keep digging deeper here.

Thanks for the hints, I most likely made a mistake somewhere.

-jeff



Jeff McKenna

unread,
Apr 15, 2016, 6:11:07 PM4/15/16
to spatiali...@googlegroups.com
Indeed my libiconv.lib does not seem to contain "local_charset". Yikes.
I'm not sure why. Sorry for this noise.

Thanks for the help today Sandro.

a.fu...@lqt.it

unread,
Apr 15, 2016, 6:23:33 PM4/15/16
to spatiali...@googlegroups.com
On Fri, 15 Apr 2016 19:11:05 -0300, Jeff McKenna wrote:
> Indeed my libiconv.lib does not seem to contain "local_charset".
> Yikes. I'm not sure why. Sorry for this noise.
>

Hi Jeff,

libiconv has a very confusing interface, that can widely
change accordingly to rather obscure configuration flags.

please have a look at the gg_utf8.c source (lines 60-79
and 84-97).
there is a damn complex conditional macro differentiating
between Linux, Apple OS-X, Android, OSGeo4W+MSVC and MinGW.

I'm pretty sure that one of the many alternative configurations
will certainly work for your own MS4W iconv.
patiently try all them by commenting/suppressing all the
conditional and manually forcing one by one
... and have a good luck :-D

my personal hint: if you've built your own iconv in the
most canonic way you are probably falling in the
"neither Mac OsX nor Android" case (i.e. linux-like)

bye Sandro

Jeff McKenna

unread,
Apr 15, 2016, 6:51:38 PM4/15/16
to spatiali...@googlegroups.com
Thanks Sandro. I did more testing, as you recommended. But then I went
back to look closely at my iconv-1.14 build, and, I discovered that I
was pointing to the wrong lib (!!!). There was a magical "static"
folder containing libiconv.lib that contains the "locale_charset" symbol. :)

Sandro I owe you a beer. A nice big, cold, very cold beer. Thank you
so much for your help. It compiled with MSVC 2015 !

:)

-jeff



Jeff McKenna

unread,
Apr 18, 2016, 10:38:06 AM4/18/16
to spatiali...@googlegroups.com
I just thought I'd give some positive feedback also: spatialite-tools
4.4.0-RC0 compile with MSVC 2015, and all 10 commandline utilities work
well. Great :)

Thanks for these great tools.
Reply all
Reply to author
Forward
0 new messages