【问题标题】:Unresolved external symbol error (LNK2019) ORTools未解决的外部符号错误 (LNK2019) ORTools
【发布时间】:2021-05-06 11:43:03
【问题描述】:

我已尝试运行此代码:

#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, numVals - 1, "y");
    IntVar* const z = solver.MakeIntVar(0, numVals - 1, "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++ compiler-errors constraint-programming or-tools


    【解决方案1】:

    你需要用 c++ 17 编译。

    你可以看看这个帖子:

    Adding OR-Tools Library to Visual Studio

    【讨论】:

    • 除非您使用路由库,否则不要使用旧的约束求解器。请改用 CP-SAT。
    • 我尝试用 c++ 17 编译并摆脱了这些错误,但现在我有:'std::allocator<:pair k> >::rebind' 错误(C4996)
    • 查看提供的 makefile。所有选项都在那里。
    • 我不明白我在哪里编译和链接这些标志。我只需要复制粘贴该代码并编译吗?
    • 您需要对之前帖子中的编译和链接标志进行逆向工程,并将其链接到可视化项目参数中。
    猜你喜欢
    • 2014-05-12
    • 2014-05-14
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 2012-10-31
    相关资源
    最近更新 更多