lundi 28 juin 2021

static and dynamic linking in one Visual Studio project [closed]

I want to link some libraries statically and others dynamically in Visual Studio. At least for learning purpose.

I want to link bullet physics statically so I linked these libs BulletDynamics.lib BulletCollision.lib LinearMath.lib Running the code:

#include "btBulletDynamicsCommon.h"
int main(int argc, char** argv)
{
    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
}

it didn't work with this log:

1>------ Build started: Project: btTest, Configuration: Release x64 ------
1>BulletCollision.lib(btDefaultCollisionConfiguration.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btConvexConvexAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btEmptyCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btConvexConcaveCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btCompoundCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btCompoundCompoundCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btConvexPlaneCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btBoxBoxCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btSphereSphereCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btSphereTriangleCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btActivatingCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btPersistentManifold.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btManifoldResult.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btPolyhedralContactClipping.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btCollisionShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btConvexShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btConvexPolyhedron.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btCollisionAlgorithm.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btPolyhedralConvexShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btSdfCollisionShape.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btHashedSimplePairCache.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>BulletCollision.lib(btMiniSDF.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>LinearMath.lib(btConvexHullComputer.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>LinearMath.lib(btGeometryUtil.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in Source.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>C:\Users\Alexey\source\repos\btTest\x64\Release\btTest.exe : fatal error LNK1319: 24 mismatches detected
1>Done building project "btTest.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So I googled my problem and I knew that Visual Studio expects dynamic linking. In order to change that behavior I changed Runtime library to Multi-threaded (/MT) in C/C++ Code Generation. And the code just worked. Which is great.

But if I am adding openGL using glfw + glad with libs glfw3.lib and opengl32.lib. Running this code (which works with default Runtime option).

#include <glad/glad.h> #include <GLFW/glfw3.h>

int main(int argc, char** argv)
{
    glfwInit();
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    }

I got this log:

1>------ Build started: Project: btTest, Configuration: Release x64 ------ 1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_strncpy 1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncpy 1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_strncpy 1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strcspn 1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strspn 1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_realloc 1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc 1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc 1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __imp___stdio_common_vsscanf 1>C:\Users\Alexey\source\repos\btTest\x64\Release\btTest.exe : fatal error LNK1120: 5 unresolved externals 1>Done building project "btTest.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So how could I use both these bullet physics openGL libraries? This is part of C++ that I really have problem with and which also scares me. So any suggestions of how I could improve in that aria will be appreciated.

Aucun commentaire:

Enregistrer un commentaire