Hi, i am working in a college (Universidad Complutense de Madrid, Spain) project with two classmates. We need to contact with OSM local maps, so libosmscout looks great.
I have build libosmscout and libosmscout-import in Visual Studio, but when i try to build Import i have 3 link errors:
1>Import.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: unsigned char __thiscall osmscout::ImportParameter::Router::GetVehicleMask(void)const " (__imp_?GetVehicleMask@Router@ImportParameter@osmscout@@QBEEXZ) referenced in function __catch$main$0
1>Import.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits\<char="">,class std::allocator\<char> > __thiscall osmscout::ImportParameter::Router::GetFilenamebase(void)const " (__imp</char></char,struct>?GetFilenamebase@Router@ImportParameter@osmscout@@QBE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) referenced in function __catch$main$0
1>Import.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osmscout::ImportParameter::Router::~Router(void)" (__imp??1Router@ImportParameter@osmscout@@QAE@XZ) referenced in function __catch$?DumpDataSize@@YA_NABVImportParameter@osmscout@@ABVImporter@2@AAVProgress@2@@Z$0
I cant figure out whats happening or what i am doing wrong, so i ask for your help if anyone know how to fix this.
Thanks.
I need some more information to help you. We have central builds for th efollowing combinations:
See https://ci.appveyor.com/project/Framstag/libosmscout
All projects are current "green" and build successfully. Which VisualStudio version and build system are you using?
I am using Visual Studio 2015. I moved files and deleted the msvc2015 prefix from the ones i want to build. I am following this tutorial, but I think is deprecated:
http://wiki.openstreetmap.org/wiki/User:Shrddr/libosmscout
I start the build process opening msvc2015_libosmscout in Windows folder under libosmscout. With the dependencies in the include folder I can build libosmscout and libosmscout-import without problems.
But when I try to build Import, sometimes I get the above error and other times it doesnt find libosmscot-import.lib, somehow the libosmscout-import.dll is generating OK, but the .lib doesnt.
¿Is there an easier way to build libosmscout, maybe with cmake or something?
Thank you very much, we are locked at this point and we cant go on with our project if we cant contact with OSM maps.
My solution was to build the libraries as static libraries (not DLLs). So - set libosmscout and libosmscout_import to build as libraries and define following: OSMSCOUT_IMPORT_EXPORT_SYMBOLS;OSMSCOUT_EXPORT_SYMBOLS
in libosmscout, libosmscout_import and import.
It's not a nice solution but it works. And while it is ok (legally) for Import to be statically linked, you'll have to make additional DLL build of libosmscout, if you'll want to use it in your app in LGPL environment.
Tried that and sucesfully built both libosmscout and libosmscout-import as .lib, but at the Import build process i got this errors in Visual:
https://s14.postimg.org/saetw6g69/617713d5163424258c98a5b99d6d367f.png
Thaks for your response.
This looks like you're missing LibXml2 library. Try building it and adding it to the linker of Import.
Yes, it was that. With libxml2.lib included in Import and libosmscout & libosmscout-import built as static libraries I am able to build import and use it via CMD.
After trying with some .osm.pbf files I was able to import one succesfully, but I think I am not using the Demos file OK or something, because I always get link errors when I try to paint a map via QT or even when I use the routing.cpp example.
Here are some of the errors that Visual give me in the routing example:
https://i.gyazo.com/a2c77a356598d07f1159ed8fcd7f655c.png
I linked the libosmscout.lib and libosmscout-import.lib the same way as I did with libxml2.lib, but it seems that they arent working.
Thanks again, you are helping me so much.
Well - if you'll be going the static library way, you'll have to build EVERY project statically. This basucally means - libraries have to be set to library output and not dll. And you'll have to take care that exports are not declared as dllexport. For the map library this would mean adding preprocessor directives
OSMSCOUT_IMPORT_EXPORT_SYMBOLS
OSMSCOUT_EXPORT_SYMBOLS
OSMSCOUT_MAP_EXPORT_SYMBOLS
While for executable files, you'll have to add at least OSMSCOUT_IMPORT_EXPORT_SYMBOLS
OSMSCOUT_EXPORT_SYMBOLS
... so the includes will not define imported functions as dllimport
Basically - whenever you will see declspec(dllimport) in linker errors, you should know that you're missing a preprocessor derective to disable dynamic linkage. The easiest way to see which is to open up the external dependencies under the project and look for XXXImportExport.h , open it up and see where something is defined as declspec(dllimport), check which missing preprocessor definitions bring you there and define them in the project.
I would suggest to use the cmake files for generating the VisualStudio 2015 files. There are at lets prooven to build (admittely the appveyor buuld does not actually try to run the binaries).
You can take a look at the appveyor configuration and builds for details.
The appveyor.yml simply starts the scripts under ci/appveyor with the given paramete rin the build matrix. So for a VisualStudio build it just downloads and installs zlib, iconv and libxml2 (install.bat) and for cmake it is just a simple:
mkdir build
cd build
cmake -G "Visual Studio 14 2015 Win64" ..
cmake --build .
I tried with cmake and it worked fine, but now what i am supossed to do?
I have this build folder:
https://i.gyazo.com/af0c37c6acd5765a58fe25774586f18c.png
If I open the libosmscout project and try to build it in Visual it gives me an error: Acces denied to ..libosmscout\build\x64\Debug\ALL_BUILD
I dont know what I should do, how i am going to import a map file if there is not Import in Build folder?
Thanks again, you are being very helpful.
I have asked on th list for further help. I would have to reactivate my Windows development environment, which would tke some time. But AFAIK other people on the list are currently trying actively to impove th eWIndows CMake build and could help faster.
Thanks Tim, dont need to reactivate your Windows development enviroment, you are already being helpful at this way.
I saw your message in the mailing lists, I was able to build import with the help of Toni, but I also saw a pull request in git, that already had built libosmscout libraries and the import tool.
Now, with a map imported OK I am trying to use the library, but I am locked here.
If I use the routing.cpp example with the libraries linked statically, i get tons of errors in Visual:
https://i.gyazo.com/a2c77a356598d07f1159ed8fcd7f655c.png
Thanks again.
My spanish (?) is non-existant, so I can only guess what the problem is. But it looks, like symbols from the libraries are not found during linking of the demo.
Under Windows - if using shared libraries/DLLs - symbols must explicitely exported during buulding of the library and explicitely marked as to be imported during build of applications that use that libraries.
In libosmsocut this is handled by the XXXImportExport.h headers that define macros like OSMSCOUT_API and similar.
For libosmscout itself, this means that during build of the library OSMSCOUT_EXPORT_SYMBOLS and (DLL_EXPORT or _WINDLL) must be defined, so that symbols are exported using __declspec(dllexport). During building against the library these symbols must not be defined, so that __declspec(dllimport) is used.
You must also link against the *.lib file of the shared library/DLL.
There likely is a tool, that should allow you to check, if symbols are correctly exported.
I hope that helps.
hi everyone, I am in this exact state with this comment: https://sourceforge.net/p/libosmscout/bugs/23/#80cd/d03f. If I open the libosmscout project and try to build it in Visual it gives me an error: Acces denied to ..libosmscout\build\x64\Debug\ALL_BUILD. I am trying to use libosmscout on windows with qt creator. I want to display a map in qtcreator with libosmscout. I built libosmscout in visual studio 2019. What should I do next? When I run example project OSMScout2 in qtcreator I get libosmscout-map-qt development package not found error. Any advices related to error and my way to display offline map in qt are appreciated. Thanks in advance.
Last edit: haziran 2023-06-20
Hi haziran. Please make a new issue in the GitHub tracker. See https://github.com/Framstag/libosmscout/issues
Please also make sure that you use the current code in the GitHub repository. The source version here at Sourceforge is old. Possibly your issue is resolved after this.
I also recommend taking a look at he GitHub automatic builds, especially https://github.com/Framstag/libosmscout/blob/master/.github/workflows/build_and%20test_on_vs2019.yml that show a possible build for cmake+vcpkg or alternatively meson (without additional dependencies)
Hope this helps!