fallahn / tmxlite

lightweight C++14 parser for Tiled tmx files
Other
393 stars 66 forks source link

Linker errors when installing #28

Closed fishyperil closed 6 years ago

fishyperil commented 6 years ago

Hey, I'm trying to install tmxlite but I'm not that experienced with adding multiple libraries to a project and making them all work together.

I added the tmxlite include to the Additional Include Directories, the "Debug Static" folder from the binaries to the Additional Library Directories and listed the libtmxlite-s-d.lib under additional dependencies.

I also added all the SFML Directories in the same way I usually add them to a project ( linked against the static debug libraries ).

I made a solution with a new project, added the main.cpp and SFMLOrthogonalLayer.hpp from the SFML example folder and tried to compile it.

However when I try to do that I get a bunch of linking errors, one of which I found especially suspicious : Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in main.obj TmxLite

I tried changing the runtime library under code generation to MD_d but then I get it the other way around ! Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in main.obj

Do you have any idea how I could solve this ? I think this might be the result of me linking the wrong kind of SFML/tmxlite files together but both the SFML libraries I linked and the tmxlite ones are static libraries. Any ideas what's going on ?

fallahn commented 6 years ago

If you're using precompiled binaries for tmxlite and sfml then they were probably compiled with different settings. Recompile one or the other (or both) so that the settings match, then make sure your own project settings match too.

fishyperil commented 6 years ago

Could you give me an example of how to do that with the tmxlite stuff you uploaded ?

I'm sorry if this seems noobish but I don't actually know how to do it myself... I'm completely self thought and I've only been programming for about a year so sometimes I don't know things that come as a given to most people.

fallahn commented 6 years ago

It sounds like you're using Visual Studio so that's what I'll assume. Clone or download the tmxlite repository to your computer. Open the visual studio solution, right click on the tmxlite project and choose properties. Make sure the configuration is set to DebugStatic, and set the runtime library as you were on your project. Do the same for ReleaseStatic. At the top of VS where the drop down contains the selection for Release and Debug builds, select configuration manager. For the release configuration set the tmxlite project to ReleaseStatic. Do the same for Debug. You can also choose here if you're building for x86 or x64. You should be able to hit build and get the compiled tmxlite library. If you get a build failure it may be because the v140 compiler tools are not installed - either upgrade the project to v141 (project properties) or install the tools from the VS2017 installer program.

For SFML it's pretty much the same, only you first have to create the VS solution with CMake. There are instructions on the SFML site. When you have the solution created you can set the runtime libraries in the same way. It's also worth noting that if you want to use static SFML libraries your project needs to define SFML_STATIC in the preprocessor options of the project properties. You also need to link a set of further libraries, listed on the SFML site (under setting up SFML for visual studio). This isn't necessary when using dll/shared libraries but you will get errors if you accidentally mix the two up.

fishyperil commented 6 years ago

Ok, great explanation, it sounds like I'll be able to figure it out. I know about SFML's usual requierments , I've been playing around with it for a few months now, learning to build a pretty basic game framework.

I'll give it a try tomorrow, I've already spent like 5 hours today trying to get it all up and running..... thanks a lot for helping out :)

fallahn commented 6 years ago

No problem, we've all been there :)

fishyperil commented 6 years ago

I've compiled both the tmxlite and the SFML libs manually and linked them together for the most part, however I'm still left with this :

1>sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol impjoyGetPosEx@8 referenced in function "public: static bool __cdecl sf::priv::JoystickImpl::isConnected(unsigned int)" (?isConnected@JoystickImpl@priv@sf@@SA_NI@Z)

1>sfml-window-s-d.lib(JoystickImpl.cpp.obj) : error LNK2019: unresolved external symbol impjoyGetDevCapsW@12 referenced in function "public: bool __thiscall sf::priv::JoystickImpl::open(unsigned int)" (?open@JoystickImpl@priv@sf@@QAE_NI@Z)

1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol imptimeGetDevCaps@8 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)

1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol imptimeBeginPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)

1>sfml-system-s-d.lib(SleepImpl.cpp.obj) : error LNK2019: unresolved external symbol imptimeEndPeriod@4 referenced in function "void __cdecl sf::priv::sleepImpl(class sf::Time)" (?sleepImpl@priv@sf@@YAXVTime@2@@Z)

I've tried linking manually compiled libraries as well as linkining manually compiled tmxlite against my usual sfml settings and I still get these same errors.... Do you know what the issue could be ?

Sorry to keep bugging :)

fallahn commented 6 years ago

These are sfml errors, probably because you're statically linking it:

Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well. This means that if you are linking sfml-window-s.lib or sfml-window-s-d.lib for example, you will also have to link opengl32.lib, winmm.lib and gdi32.lib. Some of these dependency libraries might already be listed under "Inherited values", but adding them again yourself shouldn't cause any problems.

As the errors are from sfml-system and sfml-window at a guess I'd say you're missing winmm.lib. Check the table in the link for the full list of libs :)

fishyperil commented 6 years ago

It looks like it really was the winmm.lib file ! I actually checked the lib files in my other sfml project to see if I'm missing something, and somehow I skipped that one , even though I can see that it's there now .

Well , thanks a lot man, it's up and running now - time to get down to the interesting stuff :)

fallahn commented 6 years ago

You're welcome, have fun!