Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vs2019 meet LNK2001 while using external static library yaml-cpp.lib

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?

like image 872
Okifu Nearl Avatar asked Apr 19 '26 11:04

Okifu Nearl


1 Answers

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

like image 59
Alan Birtles Avatar answered Apr 21 '26 01:04

Alan Birtles



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!