Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a shared lib that depends on velocypack gives linking error (MSVC) #60

Open
gdmiron opened this issue Dec 19, 2019 · 2 comments

Comments

@gdmiron
Copy link

gdmiron commented Dec 19, 2019

I am trying to compile a library that links to velocypack for windows using MSVC (Visual Studio) complier but I get linking errors due to the static vs dynamic symbols mismatch.

  Auto build dll exports
velocypack.lib(Version.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in DatabaseClient.obj

Could you suggest a solution? Is there a way to build a shared lib for velocypack?

it works if one changes the linker settings in \cmake\Modules\AR_CompilerSettings.cmake from MTd to MDd and MT to MD. But I am not sure if this is the right solution.

@kvahed
Copy link
Contributor

kvahed commented Dec 19, 2019 via email

@gdmiron
Copy link
Author

gdmiron commented Dec 20, 2019

Is there a way when calling cmake to overwrite this:

      set(${flag_var} "${${flag_var}} /MT")

if I do this when building velocypack:

cmake -G"Visual Studio 15 2017" -DCMAKE_CXX_FLAGS_RELEASE=/MD -DCMAKE_BUILD_TYPE=Release

the linking is still set to /MT (probably overwritten by the code above). It only works if I manually change the flag in the file.

could you add to AR_CompilerSettings.cmake something like:

elseif(MSVC) 
    message(STATUS "Compiler type MSVC: ${CMAKE_CXX_COMPILER}")
    add_definitions("-D_CRT_SECURE_NO_WARNINGS=1")

    foreach (flag_var
           CMAKE_CXX_FLAGS
           CMAKE_CXX_FLAGS_DEBUG
           CMAKE_CXX_FLAGS_RELEASE
           CMAKE_CXX_FLAGS_MINSIZEREL
           CMAKE_CXX_FLAGS_RELWITHDEBINFO)
    if (flag_var MATCHES "DEBUG")
      if (MSVC_WITH_DYNAMIC_RUNTIME)
          set(${flag_var} "${${flag_var}} /MDd")
      else()
          set(${flag_var} "${${flag_var}} /MTd")
      endif()
    else ()
      if (MSVC_WITH_DYNAMIC_RUNTIME)
          set(${flag_var} "${${flag_var}} /MD")
      else()
          set(${flag_var} "${${flag_var}} /MT")
      endif()
    endif ()
  endforeach()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants