Setting Up CPLEX in Eclipse C++ on Linux - c++

I have installed CPLEX 12.6.3 (CPLEX_Studio_Community1263) and I want to integrate CPLEX in my Eclipse C++ project (on Linux). But I don't know which steps I have to follow to include CPLEX in my project.
Even by following exactly the steps shown at this link, it still not working for me (I can't import cpelx.jar in my project). The path of my cplex.jar is
/opt/ibm/ILOG/CPLEX_Studio_Community1263/cplex/lib/cpelx.jar
When I right-click on my project and go to
Properties --> Settings --> GCC C++ Linker --> Libraries
to add the cplex.jar in my project, it is impossible to add the .jar because I can't select it (it is deselected and impossible to select it).
Can some one explain me how I can include CPLEX in my project?

The link you reference is for setting up a Java program. This will not help you.
Instead, you should try running one of the C++ examples shipped with CPLEX. Try the following (assuming your path is correct from above):
$ cd /opt/ibm/ILOG/CPLEX_Studio_Community1263/cplex/examples/x86-64_linux/static_pic
$ make ilolpex1 2>&1 | tee output.txt
This will save the output in output.txt so that you can look at it later. It should give you an idea of what the required command line arguments are.
For example, on my system (x86-64_linux), I see this in the output:
$ make ilolpex1
g++ -O0 -c -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include ../../../examples/src/cpp/ilolpex1.cpp -o ilolpex1.o
g++ -O0 -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include -L../../../lib/x86-64_linux/static_pic -L../../../../concert/lib/x86-64_linux/static_pic -o ilolpex1 ilolpex1.o -lconcert -lilocplex -lcplex -lm -lpthread
This tells you everything you need to know to compile and link your program. You'll just need to figure out where to enter this information in Eclipse.

Related

Unable to use gdb with hdf5 c++ application

I am trying to use gdb to debug an hdf5 C++ application that I have written. The h5 package that I am using was installed using conda. The command that I am using is:
h5c++ hdf5.cpp
This generates an executable which I then run with gdb as follows:
gdb a.out
gdb launches alright. But when I add breakpoint using:
b 10
or any line number, it gives a message: No line 10 in file "init.c"
When I press run, it runs the whole program at once (which I don't want) and exits. The h5c++ -show command gives the following output:
x86_64-conda_cos6-linux-gnu-c++ -I/i3c/hpcl/sms821/software/tensorflow/anaconda2/include -D_FORTIFY_SOURCE=2 -O2 -g -fvisibility-inlines-hidden -std=c++17 -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -pipe -I/i3c/hpcl/sms821/software/tensorflow/anaconda2/include -fdebug-prefix-map==/usr/local/src/conda/- -fdebug-prefix-map==/usr/local/src/conda-prefix -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_hl_cpp.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_cpp.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5_hl.a /i3c/hpcl/sms821/software/tensorflow/anaconda2/lib/libhdf5.a -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-rpath,/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -L/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib -g -lrt -lpthread -lz -ldl -lm -Wl,-rpath -Wl,/i3c/hpcl/sms821/software/tensorflow/anaconda2/lib
I think this has to do with the compiler the compiler that it is using. I tried replacing x86_64-conda_cos6-linux-gnu-c++ with my native g++ compiler in the h5c++ script but that gives linker error.
Please suggest how should make my h5 application work with gdb. Should I install hdf5 from source since I don't have sudo access? I am working on a Linux machine.
I simply installed hdf5 from the source files. While configuring the installation I turned the --enable-build-mode and --enable-symbol switches. Hdf5 has a dependency on szip which I also installed from source code. My exact configuration was as follows:
./configure --prefix=<hdf5 install directory> --enable-cxx --enable-build-mode=debug --enable-symbols=yes --enable-profiling=yes --with-szlib=<szip install directory>
The above solution worked and I was able to compile my h5 application using h5c++ hdf5.cpp and also use gdb to debug it.

Getting Cplex example to run: Undefined references

I am trying to get the Cplex basic LP example to work. The code can be found here. I am completely new with c++, but hope to be able to get this running.
I am trying to compile it on linux. I am using the following command to run it
g++ -D IL_STD -I /opt/ibm/ILOG/CPLEX_Studio1271/opl/include ilolpex1.cpp
The -D IL_STD was put there to solve an error as found here. The -I ... was put there to specify the location of the header files. I came up with this myself after a lot of trying and googling, so i am in no way sure this is correct.
Anyway, i when i run it i get errors of undefined references:
/tmp/ccl9O1YF.o: In function `populatebyrow(IloModel, IloNumVarArray, IloRangeArray)':
ilolpex1.cpp:(.text+0x18f): undefined reference to `IloNumVar::IloNumVar(IloEnv, double, double, IloNumVar::Type, char const*)'
I did not make any changes in the file, so i assume the only thing which can be wrong is how the files are linked. I have the feeling it probably just is a simple setting, but after hours of looking i still have no idea how to fix it.
The easiest way to compile the ilolpex1.cpp example is to use the Makefile that is included with the installation. For example, you should do the following:
$ cd /opt/ibm/ILOG/CPLEX_Studio1271/cplex/examples/x86-64_linux/static_pic
$ make ilolpex1
This will produce output, like the following:
g++ -O0 -c -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include ../../../examples/src/cpp/ilolpex1.cpp -o ilolpex1.o
g++ -O0 -m64 -O -fPIC -fno-strict-aliasing -fexceptions -DNDEBUG -DIL_STD -I../../../include -I../../../../concert/include -L../../../lib/x86-64_linux/static_pic -L../../../../concert/lib/x86-64_linux/static_pic -o ilolpex1 ilolpex1.o -lconcert -lilocplex -lcplex -lm -lpthread
This will tell you everything you'll need to know if you choose to compile your own application by hand in the future. The details about this are described in the documentation (e.g., here).
Obviously, the iloplex1.cpp file is just a demo how to use IloCplex.
What you yet need is IloCplex itself. This should come either as (a) further source file(s) you have to compile with the demo or as a library you link against.
Have a look at your cplex directories, you might find a lib[...].a file somewhere there, possibly in /opt/ibm/ILOG/CPLEX_Studio1271/opl/lib.
You can link against using GCC's (clang's) -l and -L options. Be aware that when using -l, you leave out lib and .a (-l [...] with above (invalid) sample name).

Running Eigen's sparse CG solver multi-threaded

I have Matlab code that uses sparse and '\' as solver for a linear system. I have hand tailored a C++ function that uses the conjage gradient sparse solver from Eigen in order to run the code outside Matlab using the coder toolbox to export the rest of the Matlab code. I export a static library and I'm able to compile and execute it on my remote system without any problem. However, I'm not able to run the code using multi-threading. I have tried to export it as a Matlab executable (mex) and the whole code runs in parallel without problem inside Matlab.
So my conclusions are that it must be something different in the compiler/linker flags on my remote system. I use -fopenmp in both complier and linker and I run the executable with OMP_NUM_THREADS=n and if I read out "n" inside my program I get the same number as I have in my execution.
My question is, do I need to include anything else in my compiler/linker, apart from needed things related to my particular code, in order to get Eigen to run multi-threaded?
UPDATE:
On the remote system I do:
g++ -c -m64 -fopenmp -std=c++11 -I /usr/local/include/Eigen/src/misc/
~/src/myHandTailoredFile.cpp -o ~/src/myHandTailoredFile.o
and with linker options
-fopenmp -L /usr/local/lib64/ -llapack -L /usr/local/lib/ -lcurl
To compile my hand tailored file together with myBigProgram into a Mex-file I do
g++ -DHAVE_LAPACK_CONFIG_H -DLAPACK_COMPLEX_STRUCTURE -DMW_HAVE_LAPACK_DECLS -c -ansi -fexceptions -fPIC -fno-omit-frame-pointer -pthread -D_GNU_SOURCE -DMATLAB_MEX_FILE -std=c++0x -fopenmp -DOMPLIBNAME="\"/usr/local/MATLAB/R2016a/sys/os/glnxa64/libiomp5.so\"" -O -DNDEBUG -I "/usr/local/MATLAB/R2016a/simulink/include" -I "/usr/local/MATLAB/R2016a/toolbox/shared/simtargets" -I "./interface" -I "/usr/local/lib" -I "/usr/local/MATLAB/R2016a/extern/include" -I "." "~/src/myHandTailoredFile.cpp"
with linker options set to
-pthread -Wl,--no-undefined -Wl,-rpath-link,/usr/local/MATLAB/R2016a/bin/glnxa64 -shared -L/usr/local/MATLAB/R2016a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++ -lcurl -fPIC -L/usr/local/MATLAB/R2016a/sys/os/glnxa64 -liomp5 -o myBigProgram_mex.mexa64 -L"/usr/local/MATLAB/R2016a/bin/glnxa64" -lmwblas -lmwlapack -lemlrt -lcovrt -lut -lmwmathutil
Note that the compiler and linker options for the later is completely defined by Matlab.

Translate CL.exe to mingw command

I have this CL.exe command
cl -Fesample.dll -Oi -LD -D NO_TRACE=1 -MT sample.cpp sample_dll.def
and i would like to compile it on Linux with MinGW and this is what i have so far
i586-mingw32msvc-gcc -Fesample.dll -shared -D NO_TRACE=1 sample.cpp sample_dll.def
Tracing down the cl command options
-Oi is optimisation -> not important at this point
-LD is for generating a dll -> replaced with -shared
-D is for setting a constant in the source -> same on both
-MT is for multithreading -> i was not able to find the mingw option for this as it seems it is not fully supported.
Am i wrong?
But it won't compile and i don't really know why.
Errors i got from testing are ether
-Cannot export samplefunction#4: symbol not defined
or when changing the command through guessing
-Error: invalid Suffix
-Warning: ‘somevariable’ initialized and declared ‘extern’
If you can help me, please do so. Thanks.
To compile a shared library from functions in a C++ code file:
g++ -o esample.so -shared -fpic -DNO_TRACE=1 sample.cpp
Multithreaded (-MT) should be the default these days.
The -LD equivalent is -fpic and -shared
Reference: http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html

g++ can't find ncurses.h despite it being installed

I'm trying to experiment around in ncurses for the first time, but I'm having problems compiling my source code. As far as I can tell, ncurses is installed and in the proper directories.
My makefile is super simple:
.cpp :
g++ -Wall -g -o $* $*.cpp -std=c++11 -lncurses
and here's my output when I try to locate ncurses.h
$ locate ncurses.h
/usr/include/ncursesw/ncurses.h
and when I check to see if it's installed
$ dpkg -l | grep ncurses
ii libncurses5:amd64 5.9+20140118-1ubuntu1 amd64 shared libraries for terminal handling
ii libncursesw5:amd64 5.9+20140118-1ubuntu1 amd64 shared libraries for terminal handling (wide character support)
ii libncursesw5-dev:amd64 5.9+20140118-1ubuntu1 amd64 developer's libraries for ncursesw
ii mtr-tiny 0.85-2 amd64 Full screen ncurses traceroute tool
ii ncurses-base 5.9+20140118-1ubuntu1 all basic terminal type definitions
ii ncurses-bin 5.9+20140118-1ubuntu1 amd64 terminal-related programs and man pages
ii ncurses-term 5.9+20140118-1ubuntu1 all additional terminal type definitions
But g++ tells me this when I try to make
bankacct.cpp:18:29: fatal error: ncurses.h: No such file or directory
compilation terminated.
Unfortunately, I've not got root access and I need to be able to compile on this machine. What are my options?
I've tried including <ncursesw/ncurses.h> based on suggestions from other users, but now g++ is giving me this error:
$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11 -lncurses
/usr/bin/ld: cannot find -lncurses
and if I try removing -lncurses it gives me this:
$ make bankacct
g++ -Wall -g -o bankacct bankacct.cpp -std=c++11
/tmp/cc8rPQfK.o: In function `main':
bankacct.cpp:23: undefined reference to `initscr'
Now I've tried linking the libraries. Here's what I did:
$ locate libncurse
/lib/x86_64-linux-gnu/libncurses.so.5
/lib/x86_64-linux-gnu/libncurses.so.5.9
/lib/x86_64-linux-gnu/libncursesw.so.5
/lib/x86_64-linux-gnu/libncursesw.so.5.9
/usr/lib/x86_64-linux-gnu/libncurses++w.a
/usr/lib/x86_64-linux-gnu/libncursesw.a
/usr/lib/x86_64-linux-gnu/libncursesw.so
/usr/share/doc/libncurses5
/usr/share/doc/libncursesw5
/usr/share/doc/libncursesw5-dev
/var/lib/dpkg/info/libncurses5:amd64.list
/var/lib/dpkg/info/libncurses5:amd64.md5sums
/var/lib/dpkg/info/libncurses5:amd64.postinst
/var/lib/dpkg/info/libncurses5:amd64.postrm
/var/lib/dpkg/info/libncurses5:amd64.shlibs
/var/lib/dpkg/info/libncurses5:amd64.symbols
/var/lib/dpkg/info/libncursesw5-dev:amd64.list
/var/lib/dpkg/info/libncursesw5-dev:amd64.md5sums
/var/lib/dpkg/info/libncursesw5-dev:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.list
/var/lib/dpkg/info/libncursesw5:amd64.md5sums
/var/lib/dpkg/info/libncursesw5:amd64.postinst
/var/lib/dpkg/info/libncursesw5:amd64.postrm
/var/lib/dpkg/info/libncursesw5:amd64.shlibs
/var/lib/dpkg/info/libncursesw5:amd64.symbols
So then I tried two variations of my makefile:
g++ -Wall -g -L/usr/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses
and
g++ -Wall -g -L/lib/x86_64-linux-gnu/ -o $* $*.cpp -std=c++11 -lncurses
which still gave me the errors undefined reference to 'initscr' (without -lncurses) or /usr/bin/ld: cannot find -lncurses (with it)
-lncurses
tells the linker to look for a library called "ncurses.". You clearly indicate that's not what your library is called:
/usr/lib/x86_64-linux-gnu/libncursesw.a
You need
-lncursesw
You don't need to modify the source code to specify <ncursesw/ncurses.h> you can simply add
-I/usr/include/ncursesw