0

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 &)" 
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Alan Birtles May 26 '22 at 17:36
  • 1
    Please show a [mre] including the full text of any error messages – Alan Birtles May 26 '22 at 17:37
  • I hope this is now reproducible, there are two out of six errors, they are all simillar. My method is there and a reference to a library that I am using. So if anyone can help, please do. – Žarko Tomičić May 28 '22 at 07:23
  • You should copy the errors from the compiler output window rather than the error list. Where exactly have you defined `YAML_CPP_STATIC_DEFINE`? Judging from the error messages you are still attempting to use the dll version of yaml-cpp – Alan Birtles May 28 '22 at 07:44
  • It is defined as a preprocessor definition in premake lua file which then sets it up in visual studio under properties, c++, preprocessor. For yaml-cpp project. – Žarko Tomičić May 28 '22 at 10:04
  • And yes, you are right, it looks like I am trying to use it but I did define this yaml static define, and you can checkout dll.h file of the lib on github. It seems that it should do the job. – Žarko Tomičić May 28 '22 at 10:17
  • Is `YAML_CPP_STATIC_DEFINE` defined when building the cpp files in `Nube.lib`? – Alan Birtles May 28 '22 at 17:19
  • No, it is defined when building project out of yaml cpp files. This generates the project with that define. But now I found out that it actually worked but generated another error because of some iterator debug level not equal to one in other projects I was building. So now it worked with that define. Reason I didn't catch it was because these new errors were also linker errors so I didn't pay attention to details. So false alarm but thanks. – Žarko Tomičić May 28 '22 at 18:36

0 Answers0