I got yaml-cpp library and I made a project out of it inside visual studio and when I tried to link with my existing project as a static lib I got an error about dllimport/export. I also have one folder in my existing project where I keep all the yaml-cpp code, so I guess I have it as a separate project but also locally, I have seen this being done that way so I just copied the procedure.
I suppose this is in order to be able to include stuff that I need?
So I found the file dll.h in my yaml-cpp project and found preprocessor definitions and changed it to static, but I still get linker errors on functions that I call in my own project. I believe that this is because I am referring to functions defined inside of my project, where dynamic preprocessor definition is still enforced. So I defined static there also but after that I got like 40 errors.So, my question is, how do I link yaml-cpp as static library? Relevant code: https://github.com/jbeder/yaml-cpp/blob/master/include/yaml-cpp/dll.h This is dll file where some preproc are defined. If you are building static library out of it, you should define YAML_CPP_STATIC_DEFINE for yaml-cpp project. Which I did. But even after that I have errors, namely for emitter class, I guess because I am using this class in some of my code. Errors for emitter constructor and destructor and some other stuff are of type unresolved external symbol declspec(dllimport). Here is the emitter class: https://github.com/jbeder/yaml-cpp/blob/master/include/yaml-cpp/emitter.h And here is some of my code:
YAML::Emitter out;
out << YAML::BeginMap;
out << YAML::Key << "Scene" << YAML::Value << "Name";
out << YAML::Key << "Entities" << YAML::Value << YAML::BeginSeq;
m_Scene->m_Registry.each([&](auto entityID) {
Entity entity = { entityID, m_Scene.get() };
SerializeEntity(out, entity);
});
out << YAML::EndSeq;
out << YAML::EndMap;
std::ofstream fout(fpath);
fout << out.c_str();
Here is the example of the error I get. It is hard to read but maybe it is about missing overloads for operators, I don't know.:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: __cdecl YAML::Emitter::Emitter(void)" (__imp_??0Emitter@YAML@@QEAA@XZ) referenced in function "public: void __cdecl SceneSerializer::serialize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?serialize@SceneSerializer@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) NoobVisual C:\eng\Nube\NoobVisual\Nube.lib(sceneSerializer.obj) 1
And this one also:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class YAML::Emitter & __cdecl YAML::Emitter::SetLocalValue(enum YAML::EMITTER_MANIP)" (__imp_?SetLocalValue@Emitter@YAML@@QEAAAEAV12@W4EMITTER_MANIP@2@@Z) referenced in function "class YAML::Emitter & __cdecl YAML::operator<<(class YAML::Emitter &,enum YAML::EMITTER_MANIP)" (??6YAML@@YAAEAVEmitter@0@AEAV10@W4EMITTER_MANIP@0@@Z) NoobVisual C:\eng\Nube\NoobVisual\Nube.lib(sceneSerializer.obj) 1
This is from the output window:
2>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
2>Nube.lib(sceneSerializer.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl YAML::Emitter::Emitter(void)" (__imp_??0Emitter@YAML@@QEAA@XZ) referenced in function "public: void __cdecl SceneSerializer::serialize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?serialize@SceneSerializer@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>Nube.lib(sceneSerializer.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl YAML::Emitter::~Emitter(void)" (__imp_??1Emitter@YAML@@QEAA@XZ) referenced in function "public: void __cdecl SceneSerializer::serialize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?serialize@SceneSerializer@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>Nube.lib(sceneSerializer.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: char const * __cdecl YAML::Emitter::c_str(void)const " (__imp_?c_str@Emitter@YAML@@QEBAPEBDXZ) referenced in function "public: void __cdecl SceneSerializer::serialize(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?serialize@SceneSerializer@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
2>Nube.lib(sceneSerializer.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class YAML::Emitter & __cdecl YAML::Emitter::SetLocalValue(enum YAML::EMITTER_MANIP)" (__imp_?SetLocalValue@Emitter@YAML@@QEAAAEAV12@W4EMITTER_MANIP@2@@Z) referenced in function "class YAML::Emitter & __cdecl YAML::operator<<(class YAML::Emitter &,enum YAML::EMITTER_MANIP)" (??6YAML@@YAAEAVEmitter@0@AEAV10@W4EMITTER_MANIP@0@@Z)
2>Nube.lib(sceneSerializer.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class YAML::Emitter & __cdecl YAML::Emitter::Write(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)"