jrouwe / JoltPhysics

A multi core friendly rigid body physics and collision detection library. Written in C++. Suitable for games and VR applications. Used by Horizon Forbidden West.
MIT License
6k stars 374 forks source link

Unresolved external error when adding HelloWorld code to project #1115

Closed Mahmoud1205 closed 1 month ago

Mahmoud1205 commented 1 month ago

Here are the first 3 errors: LNK2001 unresolved external symbol "protected: virtual void cdecl JPH::ConvexShape::RestoreBinaryState(class JPH::StreamIn &)" LNK2001 unresolved external symbol "bool (cdecl JPH::AssertFailed)(char const ,char const ,char const ,unsigned int)" LNK2001 unresolved external symbol "private: static struct JPH::PhysicsLock::LockData * JPH::PhysicsLock::sLocks"

I'm using the Debug config and I have JPH_ENABLE_ASSERTS and JPH_DEBUG_RENDERER defined in the preprocessor, and Jolt.lib is in the linker inputs. The answer to https://github.com/jrouwe/JoltPhysics/issues/987 did not help me.

jrouwe commented 1 month ago

I've not seen this error before and e.g. JPH::ConvexShape::RestoreBinaryState is a regular function that doesn't depend on any preprocessor macro. The only thing I can say with the information given is that most likely you have a mismatch in compiler/linker options between the lib and your own project. E.g. maybe you're compiling Jolt as a shared lib and linking it as a regular lib?

Mahmoud1205 commented 1 month ago

I didn't change any of the options while compiling, I'm using Visual Studio 2022, I'm linking it by adding the directory its (Jolt.lib) in to the Library Directories property in VS22 since I thought that was enough. But now that I added "Jolt.lib" to Properties > Linker > Input > Additional Dependencies theres new errors, theyre all just "mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MD_DynamicRelease' in glm.obj" repeated dozens of time, and the file doing it is Jolt.lib. Can I not use GLM alongside Jolt? And there are dozens of "unresolved external symbol _CrtDbgReport" and some other stuff, all coming from Jolt.lib... Also, compiling and running the samples in the Jolt solution works fine, so the issue is with my project setup.

jrouwe commented 1 month ago

As the error says: You're mixing runtime libraries. Jolt by default uses statically linked runtime libraries, to switch to dynamic (which your project appears to be using) set the USE_STATIC_MSVC_RUNTIME_LIBRARY cmake option while compiling Jolt to OFF.