LNK2019:未解析的外部符号(Qt + cplex)

时间:2015-03-31 08:27:04

标签: c++ qt linker cplex

我在Qt中创建一个简单的控制台应用程序(Qt Creator 3.3.2(opensource) 基于Qt 5.4.1(MSVC 2010,32位)),它使用cplex(12.3.0.0)。 代码如下:

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:错误:LNK2019:未解析的外部符号“public:double __thiscall IloAlgorithm :: getObjValue(void)const”(?getObjValue @ IloAlgorithm @@ QBENXZ)在函数_main中引用

我已经清理,关闭,重新启动,再次运行qmake,并重建......但仍然是同样的错误......

1 个答案:

答案 0 :(得分:0)

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

请参阅此链接https://msdn.microsoft.com/en-us/library/799kze2z.aspx