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
- Correctly define the required symbols to export the dll symbols under MSVC. Problem described in issue #461 — committed to mdouaihy/yaml-cpp by mdouaihy 6 years ago
- Correctly define the required symbols to export the dll symbols under MSVC. Problem described in issue #461 — committed to hunter-packages/yaml-cpp by mdouaihy 6 years ago
Having the same problem with
VS2017and Windows 8.1.INSTALLprojectincludeandlibdirectories to my own project in Project -> Properties -> VC++ and LinkerCurrent workaround is to blatantly copy the whole
includeandsrcfolders 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-cppcd yaml-cppmkdir buildcd buildcmake -G "Visual Studio 15 2017 Win64" -DBUILD_SHARED_LIBS=OFF ..YAML_CPP.slnfile located in the build folder with VS2017ALL_BUILDProperties -> VC++ Directories -> Include Directories -> Add YOUR-PATH-TO-REPOSITORY\yaml-cpp\includeProperties -> VC++ Directories -> Library Directories -> Add YOUR-PATH-TO-REPOSITORY\yaml-cpp\build\DebugProperties -> Linker -> Input -> Additional Dependencies -> Add libyaml-cppmdd.lib<yaml-cpp/yaml.h>This may be a good thing to add to the
install.txtin MSVC, try adding
YAML_CPP_DLLto your project’s Preprocessor Definitions