1

I built yaml-cpp staticly using vs2019 and got lib from path yaml-cpp-master\build\Release\yaml-cpp.lib, now I intend to add it to my own project, simple code follows:

#include <yaml-cpp/yaml.h>
#include <string>

using namespace std;

int main() {
    YAML::Node config = YAML::LoadFile("test.yaml");
    if (config["test1"]) {
        cout << config["test1"].as<string>() << endl;
    }
    return 0;
}

I've set my project properties following How to add static libraries to a Visual studio project, but I meet LNK2001 error and C4251 warning when building:

LNK2001 "__declspec(dllimport) public: __cdecl YAML::Node::Node(void)" (__imp_??0Node@YAML@@QEAA@XZ)

it seems the linker still wants dll...which is not my intention, is there any possible solutions?

1 Answers1

2

You need to #define YAML_CPP_STATIC_DEFINE before you include any yaml-cpp files or in your project processor settings.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • cool, I never had a thought on it... thank you for your answer! – Okifu Nearl Feb 16 '22 at 07:01
  • I still have linker errors even after defining this. I defined it for yaml-cpp project which I build as a static library. I have several linker errors for some functions that I am using inside my classes. Mostly it's unresolved external symbol declspec(dllimport) stuff. – Žarko Tomičić May 26 '22 at 17:23
  • @ŽarkoTomičić I suggest you post a new question with a [mre] though the answer is probably in 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:33