yaml-cpp: Unable to use yaml-cpp with MSVC 2015 with BUILD_SHARED_LIBS

Hi,

I’m compiling yaml-cpp from source with MSVC 2015, in the RelWithDebInfo x64 configuration, with BUILD_SHARED_LIBS=ON specified. The code fails to link due to lack of YAML_CPP_API on classes in exceptions.h:

6>load_node_test.obj : error LNK2019: unresolved external symbol "public: virtual __cdecl YAML::Exception::~Exception(void)" (??1Exception@YAML@@UEAA@XZ) referenced in function "public: virtual void * __cdecl YAML::Exception::`scalar deleting destructor'(unsigned int)" (??_GException@YAML@@UEAAPEAXI@Z)
6>node_spec_test.obj : error LNK2001: unresolved external symbol "public: virtual __cdecl YAML::Exception::~Exception(void)" (??1Exception@YAML@@UEAA@XZ)

and several more. These are errors from the run-tests project, but my project gives the same. Now, I can solve this for all the non-template classes quite easily, but I also get a lot of “xxx needs to have dll-interface to be used by client of class yyy” warnings. And these warnings result in linkage erros in my project:

1>Parameter.obj : error LNK2001: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > YAML::detail::node_data::empty_scalar" (?empty_scalar@node_data@detail@YAML@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A)
1>C:\Documents\src\Mars Initiative\mi-build\Output\entities.dll : fatal error LNK1120: 1 unresolved externals

empty_scalar is a static std::string in node_data, and the dll does not export std::string. I have 600+ “dll-interface” warnings, so I guess the problem is pretty broad. I guess you’re familiar with the issue, but just to make sure we’re on the same page, I’m talking about this problem: https://support.microsoft.com/en-us/help/168958/how-to-export-an-instantiation-of-a-standard-template-library-stl-class-and-a-class-that-contains-a-data-member-that-is-an-stl-object

How would you advise to proceed? 😃 Am I doing something wrong?

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 4
  • Comments: 20 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Having the same problem with VS2017 and Windows 8.1.

  • Generated with
cmake.exe .. -G "Visual Studio 15 2017"
  • Opened in VS2017 with Admin rights, Build the INSTALL project
  • Added the generated include and lib directories to my own project in Project -> Properties -> VC++ and Linker

Current workaround is to blatantly copy the whole include and src folders to my own project. At least this works for the time being 😦

EDIT: After some struggling I got it working. These were the steps (change the generator depending on your platform):

  • git clone https://github.com/jbeder/yaml-cpp
  • cd yaml-cpp
  • mkdir build
  • cd build
  • cmake -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS=OFF ..
  • Open the YAML_CPP.sln file located in the build folder with VS2017
  • Build the project ALL_BUILD
  • if you want to link against this library, go to your project:
    • Properties -> VC++ Directories -> Include Directories -> Add YOUR-PATH-TO-REPOSITORY\yaml-cpp\include
    • Properties -> VC++ Directories -> Library Directories -> Add YOUR-PATH-TO-REPOSITORY\yaml-cpp\build\Debug
    • Properties -> Linker -> Input -> Additional Dependencies -> Add libyaml-cppmdd.lib
    • use header <yaml-cpp/yaml.h>

This may be a good thing to add to the install.txt

in MSVC, try adding YAML_CPP_DLL to your project’s Preprocessor Definitions