Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Problems Compiling C++ Concert Code in Linux

    Posted Sat May 14, 2011 02:17 AM

    Originally posted by: LuisdelaTorre


    I've got some code that works in Windows in C++ just fine, and when I tried to compile it on my department's linux server, I'm getting errors I don't recognize. I'm thinking it might be related to my makefile (I'm not too experienced in making them). Below I've posted the Makefile, the error I'm getting, and the code that gives me the error. Any help is appreciated. Thanks.

    SYSTEM     = x86-64_debian4.0_4.1
    LIBFORMAT  = static_pic
     
    #------------------------------------------------------------
    #
    # When you adapt this makefile to compile your CPLEX programs
    # please copy this makefile and set CPLEXDIR and CONCERTDIR to
    # the directories where CPLEX and CONCERT are installed.
    #
    #------------------------------------------------------------
     
    CPLEXDIR      = /share/apps/cplex/cplex121
    CONCERTDIR    = /share/apps/cplex/concert29
    # ---------------------------------------------------------------------
    # Compiler selection 
    # ---------------------------------------------------------------------
     
    CCC = g++
     
    # ---------------------------------------------------------------------
    # Compiler options 
    # ---------------------------------------------------------------------
     
    CCOPT = -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD
     
    # ---------------------------------------------------------------------
    # Link options and libraries
    # ---------------------------------------------------------------------
     
    CPLEXBINDIR   = $(CPLEXDIR)/bin/$(BINDIST)
    CPLEXJARDIR   = $(CPLEXDIR)/lib/cplex.jar
    CPLEXLIBDIR   = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
    CONCERTLIBDIR = $(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
     
    CCLNFLAGS = -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -lm -pthread
    CLNFLAGS  = -L$(CPLEXLIBDIR) -lcplex -lm -pthread
     
     
    all:
            make all_cpp
     
    CONCERTINCDIR = $(CONCERTDIR)/include
    CPLEXINCDIR   = $(CPLEXDIR)/include
     
    CCFLAGS = $(CCOPT) -I$(CPLEXINCDIR) -I$(CONCERTINCDIR) 
     
    #------------------------------------------------------------
    #  make all      : to compile the examples. 
    #  make execute  : to compile and execute the examples.
    #------------------------------------------------------------
     
     
     
    all_cpp: SAATest
     
    SAATest: main.o
            g++ main.o -o SAATest
     
    main.o: main.cpp
            g++ $(CCFLAGS) main.cpp
     
    # ------------------------------------------------------------
     
    clean:
            rm *o SAATest
     
    # ------------------------------------------------------------
    


    [luisdlt@euler SAATest]$ make all
    make all_cpp
    make[1]: Entering directory `/home/luisdlt/SAATest'
    g++ -m64 -O -fPIC -fexceptions -DNDEBUG -DIL_STD -I/share/apps/cplex/cplex121/include -I/share/apps/cplex/concert29/include  main.cpp
    /tmp/cc8Q0RNV.o: In function `main':
    main.cpp:(.text+0x70): undefined reference to `IloEnv::IloEnv()'
    collect2: ld returned 1 exit status
    make[1]: *** [main.o] Error 1
    make[1]: Leaving directory `/home/luisdlt/SAATest'
    make: *** [all] Error 2
    


    #include <ilcplex/ilocplex.h>
     
    ILOSTLBEGIN
     
     
    int main() {
      IloEnv env;
      return 0;
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Problems Compiling C++ Concert Code in Linux

    Posted Mon May 16, 2011 02:44 AM

    Originally posted by: SystemAdmin


    Your Makefile is wrong. First of all, the target for building the object file is missing a '-c' flag. It should look like this:
    main.o: main.cpp
            g++ $(CCFLAGS) -c main.cpp
    

    I usually prefer the more general form:
    %.o: %.cpp
            g++ $(CCFLAGS) -c -o $@ $<
    

    this way you don't have to write a separate rule for each source file.

    The second problem are the missing linker flags for the rule that builds the executable. This should look like that:
    SAATest: main.o
            g++ main.o -o SAATest $(CCLNFLAGS)
    

    #CPLEXOptimizers
    #DecisionOptimization