mapbox / windows-builds

DEPRECATED! build scripts for mapnik dependencies, mapnik, node-mapnik, node, libosmiom, osmium-tool
38 stars 22 forks source link

Unresolved externals from mapnik.lib #75

Closed bmharper closed 8 years ago

bmharper commented 8 years ago

After successfully building Mapnik, I'm trying to build the C++ example "rundemo.cpp". rundemo.cpp compiles fine, but when linking, I get a bunch of unresolved external symbols. I can't explain this, because when I spot check a few of these symbols, I can find them inside the exports section of mapnik.lib. Is this perhaps a VS 2015 bug that somebody has seen before?

Here is one example of a failed symbol: error LNK2001: unresolved external symbol "private: static struct std::atomic mapnik::singleton<class mapnik::datasourcecache,class mapnik::CreateStatic>::destroyed" (?destroyed_@?$singleton@Vdatasource_cache@mapnik@@VCreateStatic@2@@mapnik@@0U?$atomic@_N@std@@A)

I use dumpbin /exports mapnik.lib to discover all exported symbols, and inside it, I can find the above mentioned symbol. If it wasn't for this fact, I would keep on digging, but this has me stumped.

This is my compile line:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\vc\bin\amd64\cl.exe" /c /D_WIN32 /D__STDC_LIMIT_MACROS /DNOMINMAX /D_WIN32 /DWIN32 /D_WIN64 /DWIN64 /DNDEBUG /I"third_party\mapnik\include" /FS /W3 /EHsc /Gm- /GS /Zo /Ox /FS /MD /Zi rundemo.cpp

And this is my link line:

"C:\Program Files (x86)\Microsoft Visual Studio 14.0\vc\bin\amd64\link.exe" /DEBUG /MACHINE:X64 /NXCOMPAT /DYNAMICBASE /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF /RELEASE /LIBPATH:"third_party\mapnik\lib" "mapnik.lib" "msvcrt.lib" "msvcprt.lib" "comsuppw.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "advapi32.lib" "shell32.lib" "comctl32.lib" "uuid.lib" "ole32.lib" "oleaut32.lib" "shlwapi.lib" "OLDNAMES.lib" "wldap32.lib" "wsock32.lib" "Psapi.lib" "Msimg32.lib" "Comdlg32.lib" "RpcRT4.lib" "Iphlpapi.lib" "Delayimp.lib" rundemo.obj /out:"rundemo.exe"

I get 50 undefined symbols. Many of them are similar to the one that I mentioned at the top of the post. My compiler version is 19.00.23506 for x64 OS is Windows 10. Branch of windows-builds is 1a23e5edd7520ab40107d8a33851bbb59d30e28b Branch of mapnik is v3.0.9

jc101 commented 8 years ago

I had some trouble getting the demo working too but having just recompiled Mapnik from scratch, it is possible to get the demo built. (Note that I used "MAPNIKBRANCH=c786ff9edf8bb9cfd20aebe5bcdbd5a963f19e3d" as a parameter to settings.bat because of a current build breakage - see https://github.com/mapbox/windows-builds/issues/76#issuecomment-178550394)

I created the VS project as suggested in the demo c++ folder README.md, using something like

C:\python27\scripts\gyp rundemo.gyp --depth=. -f msvs -G msvs_version=2015

(Note: msvs_version needs to be changed from 2010). Then within the project I had to change the platforms from Win32 to x64. I think this may one of the sources of your problems as attempting to compile with a Win32 platform caused me 50 failed symbols.

Note that the gyp-generated project has a lot of different compile and link flags to the ones you're using which may cause other problems too. Eg for a DEBUG version I'm using:

Compiler: /GS /W1 /Zc:wchar_t /I"C:\Mapnik3\include" /I"C:\Mapnik3\include\mapnik\agg" /I"C:\Mapnik3\include\cairo" /I"C:\Mapnik3\include\freetype2" /I"C:\Mapnik3\include\google" /I"C:\Mapnik3\include\libxml2" /Zi /Gm- /O2 /Fd"Debug\obj\rundemo\vc140.pdb" /Zc:inline /fp:precise /D "LINUX" /D "_WINDOWS" /D "BOOST_ALL_NO_LIB" /D "BOOST_MSVC_ENABLE_2014_JUN_CTP" /D "BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES" /D "HAVE_JPEG" /D "HAVE_PNG" /D "HAVE_WEBP" /D "HAVE_TIFF" /D "MAPNIK_USE_PROJ4" /D "BOOST_REGEX_HAS_ICU" /D "GRID_RENDERER" /D "SVG_RENDERER" /D "MAPNIK_THREADSAFE" /D "BIGINT" /D "HAVE_LIBXML2" /D "HAVE_CAIRO" /D "LIBXML_STATIC" /errorReport:prompt /WX- /Zc:forScope /Gd /MD /Fa"Debug\obj\rundemo\" /EHsc /nologo /Fo"Debug\obj\rundemo\" /Fp"Debug\obj\rundemo\rundemo.pch"

Linker /OUT:"C:\Mapnik3\demo\c++\Debug\rundemo.exe" /MANIFEST /NXCOMPAT /PDB:"C:\Mapnik3\demo\c++\Debug\rundemo.pdb" /DYNAMICBASE "mapnik.lib" "boost_python-vc140-mt-1_59.lib" "cairo-static.lib" "cairo.lib" "freetype.lib" "gdal_i.lib" "harfbuzz.lib" "icudt.lib" "icuin.lib" "icuuc.lib" "jpeg.lib" "libboost_chrono-vc140-mt-1_59.lib" "libboost_date_time-vc140-mt-1_59.lib" "libboost_filesystem-vc140-mt-1_59.lib" "libboost_iostreams-vc140-mt-1_59.lib" "libboost_prg_exec_monitor-vc140-mt-1_59.lib" "libboost_program_options-vc140-mt-1_59.lib" "libboost_regex-vc140-mt-1_59.lib" "libboost_system-vc140-mt-1_59.lib" "libboost_test_exec_monitor-vc140-mt-1_59.lib" "libboost_thread-vc140-mt-1_59.lib" "libboost_timer-vc140-mt-1_59.lib" "libboost_unit_test_framework-vc140-mt-1_59.lib" "libboost_zlib-vc140-mt-1_59.lib" "libexpat.lib" "libpng16.lib" "libpq.lib" "libprotobuf-lite.lib" "libtiff_i.lib" "libwebp_dll.lib" "mapnik-json.lib" "mapnik-wkt.lib" "proj.lib" "python27.lib" "sqlite3.lib" "zlib.lib" "zlibwapi.lib" "ws2_32.lib" /DEBUG /MACHINE:X64 /PGD:"C:\Mapnik3\demo\c++\Debug\rundemo.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\obj\rundemo\rundemo.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"C:\Mapnik3\lib" /TLBID:1

I also needed to make some changes to the source code: hardcoding the datasource and font paths in lines 57 and 58:

datasource_cache::instance().register_datasources("C:\\mapnik3\\lib\\mapnik\\input"); freetype_engine::register_font("C:\\mapnik3\\lib\\mapnik\\fonts\\DejaVuSans.ttf");

and commenting out the p["encoding"] bits at lines 233 and 298.

Finally, you should run the executable from the top level Mapnik folder or change the layer paths on eg lines 232, 246, etc.

wilhelmberg commented 8 years ago

Sorry, I missed this issue. @jc101 thanks for reporting, will look into it. BTW: latest master should be good to go again. Just had a successful build.

bmharper commented 8 years ago

Thanks so much for the detailed post(s). I'll try tonight when I'm at that machine again, and post my feedback here.

bmharper commented 8 years ago

Thanks again for the help. I've managed to get the demo building. For the record, I was missing two crucial #defines: "_WINDOWS" and "BIGINT". It's really my fault not trying the gyp route first, and checking it's build configuration output.