I have written a C++ code that calls a solver called CPLEX to solve an integer linear optimization problem (under Ubuntu 18.04). I have three sets of data and I use make command to create 3 excecutables for each one of them. I then run these three executables at the same time.

My question is, does the fact that CPLEX libraries are used to create object files and the executable means that the excecutables will use CPLEX in the run time? In other words, is calling CPLEX a one-time procedure that is required only at the time of generating executables? If this is not the case, then running the three programs at the same time may not work or if it works it may affect the performance because they want to use CPLEX at the same time. Is that correct? What about using CPLEX with an interpreted programming language such as Python? I am not quite familiar with compilers or interpreters so some general explanation on how this works would be appreciated.


My .cpp source code starts with the following:

#include <iostream>
#include <fstream>
#include <time.h>
#include <math.h>
#include <vector>
#include <random>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stdlib.h>
#include <deque>
#include <ilcplex/ilocplex.h>
using namespace std ;

So all I do is add #include <ilcplex/ilocplex.h> to my source code to be able to use CPLEX libraries withing my code. In other words, my code is just a typical C++ code that uses some additional methods from CPLEX. I could provide more details about using CPLEX withing the code but I think it is irrelevant here and it does not contribute to clarity of the question. Please let me know if you need more information to understand the question.

According to this link,

When you compile a C++ application with a C++ library like CPLEX in Concert Technology, you need to tell your compiler where to find the CPLEX and Concert include files (that is, the header files), and you also need to tell the linker where to find the CPLEX and Concert libraries. The sample projects and makefiles illustrate how to carry out these crucial steps for the examples in the standard distribution. They use relative path names to indicate to the compiler where the header files are, and to the linker where the libraries are.

  • 1
    Is this what you mean by CPLEX? ibm.com/support/knowledgecenter/SSSA5P_12.6.0/… (or is CPLEX something else?) Is CPLEX a shared library? There are different ways to implement this -- could you provide a specific example? – michael Sep 16 '18 at 9:57
  • Are you writing that C++ application? I assume that yes, but your question is unclear. Please edit your question to improve it. – Basile Starynkevitch Sep 16 '18 at 11:05
  • @michael Yes, that is the CPLEX software that I meant. – Opt Sep 16 '18 at 12:33
  • @BasileStarynkevitch Yes, I wrote it and I have the source code. I will provide an example in my question. Sorry for the confusion. – Opt Sep 16 '18 at 12:35
  • @michael Here is a link to CPLEX C++ tutorial: ibm.com/support/knowledgecenter/SSSA5P_12.8.0/… – Opt Sep 16 '18 at 12:42

Writing an application that calls another application for some tasks

In pure standard C++11 (see n3337) alone, you cannot do that (because the standard don't even mention "other applications"). You might use in practice std::system (but notice that the C++11 standard don't really define what std::system exactly and concretely does, it just mentions some command processor). On Linux, that function (i.e. system(3)) uses the standard shell /bin/sh to interpret some shell command, and you could start another process in that fashion (by giving it an appropriate string). Of course on other OSes (e.g. Windows) std::system behaves differently (the syntax and semantics of commands is different; even the name of applications is different).

On Linux, you might also use popen(3). Then you are able to e.g. get the output of a command.

In general, you care about operating system facilities providing the ability to start processes and do inter-process communications with them. Details are of course OS specific and requires an entire book to be explained (so I don't have space or time to give details here). For Linux, read a good Linux programming book, such as the old ALP (then read syscalls(2))

It is likely that your C++ code would be tied to a particular operating system (concretely to Linux; so your C++ code won't even compile on Windows, and even when it does, it won't work as you want without a lot of precautions from your part). You might interested in frameworks like POCO or Qt providing some more or less common abstractions above these OSes.

You might need to spend several weeks reading about OSes. I recommend the Operating Systems: Three Easy Pieces textbook (freely downloadable).

  • I definitely need to read that textbook! You can use CPLEX in Windows and OS X as well. All you need to do is add the particular library (#include <ilcplex/ilocplex.h>) in your source code. I think what you mentioned here is already done by its developers! – Opt Sep 16 '18 at 13:05
  • My question is, after you used CPLEX to obtain the executable file (which is just zero-ones?), the executable file should run even if you uninstall CPLEX. Is that correct? What about interpreted languages like Python which typically do not give object files and executable? – Opt Sep 16 '18 at 13:12
  • It depends how your executable is linked. Most of them use shared libraries – Basile Starynkevitch Sep 16 '18 at 17:23
  • Regarding Python, it is often compiled to bytecode – Basile Starynkevitch Sep 16 '18 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.