3

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 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

6 Comments

cool, I never had a thought on it... thank you for your answer!
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.
@ŽarkoTomičić I suggest you post a new question with a minimal reproducible example though the answer is probably in stackoverflow.com/questions/12573816/…
This worked for me, but where is this documented? How is one supposed to know to do this without Googling and ending up here?
@Arrow_Raider it doesn't seem to be, you could always raise an issue or pull request on the yaml-cpp project to fix it. They probably just expect people to import their library via cmake which i assume will set this automatically
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.