【问题标题】:LNK2019: unresolved external symbol ( Qt + cplex )LNK2019:未解析的外部符号(Qt + cplex)
【发布时间】:2015-03-31 17:25:31
【问题描述】:

我正在 Qt 中制作一个简单的控制台应用程序(Qt Creator 3.3.2(开源) 基于使用 cplex (12.3.0.0) 的 Qt 5.4.1 (MSVC 2010, 32 bit))。 代码如下:

SimpelConsole.pro

QT       += core    
QT       -= gui

TARGET = SimpelConsole
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app    
SOURCES += main.cpp

INCLUDEPATH += C:\ILOG\CPLEX123\cplex\include
INCLUDEPATH += C:\ILOG\CPLEX123\concert\include
INCLUDEPATH += C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include
DEFINES += IL_STD

#// cplex123.lib library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda/ -lcplex123    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda

#// ilocplex library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda/ -lilocplex    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/cplex/lib/x64_windows_vs2010/stat_mda

#// concert.lib library
win32: LIBS += -L$$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda/ -lconcert    
INCLUDEPATH += $$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda
DEPENDPATH += $$PWD/../../../../../ILOG/CPLEX123/concert/lib/x64_windows_vs2010/stat_mda

main.cpp

#include <QCoreApplication>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ilcplex/ilocplex.h>
#include <ilcplex/cplex.h>

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);

    double elapsed_time; clock_t start_time;
    start_time= clock();
    int i, j;    
    int nbCities = 5;
    int nbOvens = 2;

    double d[2][5];
    d[0][0]= 130; d[0][1]= 70; d[0][2]= 50;  d[0][3]= 100; d[0][4]= 150;
    d[1][0]= 90;  d[1][1]= 70; d[1][2]= 250; d[1][3]= 130; d[1][4]= 200;
    double a[5];
    a[0]=240000;  a[1]=240000; a[2]=240000;  a[3]=240000;  a[4]=240000;
    double c[2];
    c[0]=500000; c[1]=15000000;
    double f[2];
    f[0] = 80; f[1] = 100;
    int cost = 1; // transport cost

    IloEnv env; // create the environment
    try{
        IloModel model(env);                       // create a model
        IloNumVarArray variables(env);             // create variable set
        IloRangeArray constraints(env);            // create constraint set
        IloObjective objective = IloMinimize(env); // create objective function

        // Build variables
        char jchar[3], name[15];
        for (j=0; j!=nbCities*nbOvens; j++){
            strcpy(name, "x_");
            itoa(j, jchar, 10);
            strcat(name, jchar);
            IloNumVar xVar(env, 0, 1, ILOINT, name);
            variables.add(xVar);
        }

        // Build constraints
        for (i=0; i!=nbOvens; i++){
            strcpy(name, "cap_restr_");
            itoa(i, jchar, 10);
            strcat(name, jchar);
            constraints.add(IloRange(env, -IloInfinity, c[i], name));
        }
        for (i=0; i!=nbCities; i++){
            strcpy(name, "flow_restr_");
            itoa(i, jchar, 10);
            strcat(name, jchar);
            constraints.add(IloRange(env, 1, 1, name));
        }

        // Set constraints coefficients
        for (i=0; i!=nbOvens; i++){
            for (j= 0; j!= nbCities; j++){
                constraints[i].setLinearCoef(variables[j+i*nbCities], a[j]);  // cannot exceed capacity - constraint
            }
        }
        for (i=0; i!=nbCities; i++){
            for (j=0; j!=nbOvens; j++){                    constraints[nbOvens+i].setLinearCoef(variables[i+j*nbCities], 1);        // flow constraint
            }
        }

        // Build objective function
        for (i=0; i!=nbOvens; i++){
            for (j=0; j!=nbCities; j++){
                objective.setLinearCoef(variables[i*nbCities+j], cost*a[j]*d[i][j]+f[i]*a[j]);
            }
        }

        model.add(objective);
        model.add(constraints); // variables are included implicitly
        IloCplex cplex(model);
        cplex.exportModel("model.lp"); // write the model to a file
        cplex.solve();

        double intTolerance = cplex.getParam(IloCplex::EpInt);

        IloNumArray values(env);
        double obj = cplex.getObjValue();
        printf("Objective value: %3.2f\n",obj);
        cplex.getValues(values, variables);
        int total = 0;
        for (j=0; j!=nbOvens*nbCities; j++){
            if (values[j] > intTolerance){
                printf("Object %d \n", j);
            }
        }

    }catch(IloException &e){
        std::cerr << "Concert exception caught: " << e << std::endl;
    }
    env.end(); // destroy the environment (to free memory)

    printf("Press Enter to continue...\n");
    getchar();

    return app.exec();
}

这是一个简单的分配模型。构建时,我收到 32 个错误,例如:

main.obj:-1: error: LNK2019: unresolved external symbol "public: double __thiscall IloAlgorithm::getObjValue(void)const" (?getObjValue@IloAlgorithm@@QBENXZ) 在函数 _main 中引用

我已经清理、关闭、重新启动、再次运行 qmake 并重建...但仍然出现相同的错误...

【问题讨论】:

    标签: c++ qt linker cplex


    【解决方案1】:

    看起来您的项目没有引用具有 IloAlgorithm 类的库。请检查您的库和调用转换。库可以在 cdecl 或 stdcall 中编译。

    也参考这个链接https://msdn.microsoft.com/en-us/library/799kze2z.aspx

    【讨论】:

      猜你喜欢
      • 2014-11-07
      • 2013-06-01
      • 1970-01-01
      • 2022-01-06
      • 2014-09-19
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      相关资源
      最近更新 更多