fallahn / sfml-tmxloader

SFML 2.x based tmx tilemap parser for files created with Tiled tile map editor
106 stars 33 forks source link

Unresolved external symbol #68

Closed kraxarn closed 8 years ago

kraxarn commented 8 years ago

Using Visual Studio 2015, I can include the file MapLoader.h and plugixml.h just fine, but after adding tmx::MapLoader ml("maps\\"); the compiler crashes with this error: Error LNK2019 unresolved external symbol "public: __cdecl tmx::MapLoader::MapLoader(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned char)" (??0MapLoader@tmx@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@E@Z) referenced in function "void __cdecl 'dynamic initializer for 'ml''(void)" (??__Eml@@YAXXZ) Not sure what I'm doing wrong or if it's a bug :/

fallahn commented 8 years ago

How are you including the rest of the library? This error is basically saying 'your header tells me the maploader exists, but I can't find it anywhere'. You need to either build the map loader as a .lib file (the simplest/most reliable way being via the cmake file in the 'next' branch) and link it to your project, or you can include the .cpp files directly. Make sure they are somewhere near the rest of your source files, then right click on the source folder in visual studio and select 'add existing'. Add each one of the .cpp files, omitting tmx2box2d if you're not using the box2d library. There is an example on the wiki here.

kraxarn commented 8 years ago

I tried building with CMake, but it keeps giving me the error

CMake Error at cmake/Modules/FindSFML.cmake:349 (message):
  SFML found but version too low (requested: 2, found: 1.x.x)
Call Stack (most recent call first):
  CMakeLists.txt:94 (find_package)

which doesn't make any sense, since I'm using version 2.3.2

fallahn commented 8 years ago

Have you tried the method of including the .cpp files?

kraxarn commented 8 years ago

If I try including the cpp files, I just get a lot of unresolved external symbol errors, most of them from MapLoaderPrivate.obj

fallahn commented 8 years ago

Are you also linking zlib?

kraxarn commented 8 years ago

I built and linked zlibstat.lib

EDIT: Silly me, forgot to include pugixml.cpp... It works now, but I get 118 warnings when compiling. Most of them being code C4275 "non dll-interface class 'sf::...' used as base for dll-interface class ...". Don't know if that's something I have to worry about or not.

EDIT 2: Btw, does the spritesheet need to be in the same folder as the .tmx file? Even if the spritesheet is set to be in another folder, it still looks for it in the same folder as the .tmx file. Also, there's still this issue of cmake not working under Windows...

fallahn commented 8 years ago

OK, glad you got it working. Is this the CMake file from the master or next branch? The next branch contains quite a few fixes, although the CMake file is generally directed at linux/gcc builds. There is a Visual Studio solution in the repository set up to build both static and shared versions of the the library. If the CMake bug is in the next branch feel free to post an issue as a bug.

The loader reads the path of sprite sheets directly from the map file, so generally relative to the current working directory. For example you have a maps directory which is your working directory, and an images directory next to it containing your textures, the map file needs to have the path

 '../images/mytex.png'.

The dll warnings are only pertinent if you're building a shared library. Including the source directly shouldn't matter, and the warnings can be surpressed with something like

#pragma warning(disable:C4275)
kraxarn commented 8 years ago

Tried the CMake from the next branch on Windows 7 with VS2015. Tried the same on Ubuntu 16.04 where it compiled just fine, so the Linux version works just fine. Not a big issue, but I can open a new issue for it if you want, but since this works now, it's nothing that has to be fixed really.

I have an assets folder where all assets are in. In that folder, I have one folder named "maps" and one "spritesheets". The tmx file in the maps folder points to "../spritesheets/ground.png", but it still tried to look for the ground.png file in the maps folder.

fallahn commented 8 years ago

OK, the image thing might be an issue, if I get the time I'll take a look over the weekend. Thanks for the feedback!

kraxarn commented 8 years ago

Thanks for helping me and creating this :+1: Keep me updated if you find the issue!

fallahn commented 8 years ago

On line 288 of MapLoaderPrivete.cpp and again on line 354 there is this:

std::string imageName = fileFromPath(c.attribute("source").as_string());

I'm not sure why I decided to reduce the file path to just the image name, but if you remove the call to fileFromPath() and use the path property directly it should load your images properly. It might also break something else though... give it a try and let me know if it works :)

kraxarn commented 8 years ago

Yup that was it! From quick testing, everything seems to work just fine. The map and all layers load properly. Thanks a lot!