Jun 10, 2011

A clean MakeFile for a C++ project using ILOG Cplex + Concert Library

Most of people that want to create IBM - ILOG Cplex project using C++ on linux, they take a file in the example directory of Cplex and copy paste it in the same example directory and then add a new entry in the Makefile as they are adding a new example.

But if you what to create a clean project an a separate directory you have to create your own Make File here is an example Make file that I did , it will automatically scan the (Source file directory )

Here is the architecture of the normal C++ in my sense ( it would be better to have header files in a separate directory, but I started the project using Visual studio on windows)

Project Directory
|__ MakeFile
|__src (dir)
| |__cpp(dir)
| |__ CPP Files + H Files
|__ *.dat ; *.xml ;*.mps Files ( The instances of the problem that you want to test)

Of course you can add separate include directory but I put my Header files with the sources (sorry again for that it’s partially the VS fault ) but in the Makefile its already build to have a separate header Files .

You need to change the EXDIR and point it to where you want build the executables and run them.

If you are using 64 bit machine or itanium you can change the SYSTEM for x86_sles10_4.1, you can find this value in the make file in the cplex example direcory.

And also you need to change the ILOGSTUDIODIR to where you have installed ILOG.

NB: Dont forget to change the envirnment variable and add the path for the ILM.

You should update your ./bash_rc file and and something similare to : (watch out for the architecture 32 or 64 and change the library path accordinly
export ILOG_HOME=/home/balbaki/ILOG/CPLEX_Studio_AcademicResearch122

export LD_LIBRARY_PATH=$ILOG_HOME/cplex/bin/x86-64_sles10_4.1/:$LD_LIBRARY_PATH

export ILOG_LICENSE_FILE=/home/balbaki/ILOG/ILM/access.ilm

This make file was build for the IBM -ILOG Cplex v 12.2 but i think it should work on the previous versions as well

# For Cplex + Concert Projects
# by Hassan Baalbaki www.hassanbaalbaki.com

SYSTEM = x86_sles10_4.1
LIBFORMAT = static_pic

EXDIR = /home/hb/dev/GlobalPlanner/MIP

# 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.
ILOGSTUDIODIR =/home/hb/ILOG/CPLEX_Studio_AcademicResearch122

# ---------------------------------------------------------------------
# Compiler selection
# ---------------------------------------------------------------------

CCC = g++
CC = gcc
JAVAC = javac

# ---------------------------------------------------------------------
# Compiler options
# ---------------------------------------------------------------------

CCOPT = -m32 -O -fPIC -fexceptions -DNDEBUG -DIL_STD

# ---------------------------------------------------------------------
# Link options and libraries
# ---------------------------------------------------------------------


CCLNFLAGS = -L$(CPLEXLIBDIR) -lilocplex -lcplex -L$(CONCERTLIBDIR) -lconcert -m32 -lm -pthread

make all_cpp

execute: all
make execute_cpp


#EXINC = $(EXDIR)/include
EXINC = $(EXDIR)/src/cpp
EXDATA = $(EXDIR)/data
EXSRCCPP = $(EXDIR)/src/cpp


#Build and Execute directory


SOURCES = ${wildcard ${SRC_PATH}/*.cpp}
OBJECTS = ${patsubst ${SRC_PATH}/%.cpp, ${OBJ_PATH}/%.o, ${SOURCES}}



# make all : to compile all.
# make execute : to compile and execute some instances

CPP_EX = globalplanner

all_cpp: $(CPP_EX)

execute_cpp: $(CPP_EX)
./globalplanner $(EXDATA)/small.dat 3

# ------------------------------------------------------------

clean :
/bin/rm -rf *.o *~ $(OBJ_PATH)/*.o
/bin/rm -rf ${SRC_PATH}/*~
/bin/rm -rf $(CPP_EX)
/bin/rm -rf *.mps *.ord *.sos *.lp *.sav *.net *.msg *.log *.clp

# ------------------------------------------------------------
# The Cpp and *.o Files

all: ${DIRS} globalplanner

mkdir -p $@

${OBJ_PATH}/%.o : ${SRC_PATH}/%.cpp
$(CCC) ${INCLUDES} -c $(CCFLAGS) $< -o $@

globalplanner: ${OBJECTS}
$(CCC) $(CCFLAGS) $^ -o globalplanner $(CCLNFLAGS)

# Local Variables:
# mode: makefile
# End:

#======================== END OF MakeFile =========================

No comments: