微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

未解决的外部符号错误 (LNK2019) ORTools

如何解决未解决的外部符号错误 (LNK2019) ORTools

我已尝试运行此代码

#include "ortools/include/ortools/base/logging.h"
#include "ortools/include/ortools/constraint_solver/constraint_solver.h"

using namespace operations_research;
    void runconstraintProgrammingExample() {
    // Instantiate the solver.
    Solver solver("ConstraintProgrammingExample");
    const int64 numVals = 3;

    // Define decision variables.
    Intvar* const x = solver.MakeIntvar(0,numVals - 1,"x");
    Intvar* const y = solver.MakeIntvar(0,"y");
    Intvar* const z = solver.MakeIntvar(0,"z");

    // Define constraints.
    std::vector<Intvar*> xyvars = { x,y };
    solver.AddConstraint(solver.MakeAllDifferent(xyvars));

    // Create decision builder to search for solutions.
    std::vector<Intvar*> allvars = { x,y,z };
    DecisionBuilder* const db = solver.MakePhase(
        allvars,Solver::CHOOSE_FirsT_UNBOUND,Solver::ASSIGN_MIN_VALUE);

    bool has_result = solver.solve(db);
    // Check that the problem has a solution.
    if (has_result != true) {
        //LOG(FATAL) << "The problem does not have a solution!";
    }
    int count = 0;
    while (solver.NextSolution()) {
        count++;
        //LOG(INFO) << "Solution " << count << ":";
        //LOG(INFO) << "x = " << x->Value()
           // << " ; y = " << y->Value()
            //<< " ; z = " << z->Value();
    }
    //LOG(INFO) << "Number of solutions: " << count;
    //LOG(INFO) << "";
    //LOG(INFO) << "Advanced usage:";
    //LOG(INFO) << "Problem solved in " << solver.wall_time() << "ms";
}
// namespace operations_research 

int main(int argc,char** argv) {
    //google::InitGoogleLogging(argv[0]);
    //FLAGS_logtostderr = 1;
    runconstraintProgrammingExample();
    return 0;
}

但我收到 9 个未解决的外部符号错误 (LNK2019)

错误 LNK2019 未解析的外部符号“public: __thiscall operations_research::Solver::Solver(class std::basic_string const &)” (??0Solver@operations_research @@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 引用在函数“void __cdecl runconstraintProgrammingExample(void)” (?runconstraintProgrammingExample@ @YAXXZ)

我尝试将来自 ortools 的包含文件放入项目的其他包含目录中,并且我还尝试将 ortools 库放入属性中的链接器输入中。还是没用。我还尝试将其修改为 x64 put 然后我得到 200 个左右的错误。我还能尝试什么?

解决方法

您需要使用 C++ 17 进行编译。

你可以看看这篇文章:

Adding OR-Tools Library to Visual Studio

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。