Cplex in C++: cannot open this source file - c++

I am learning concert technology, I am still at the beginning. I tried to open one of the examples (Ilolpex1.ccp) but when I run it the program says:
#include <ilcplex/ilocplex.h> : cannot open this source file
how can I solve this problem?

Assuming your C++11 compiler is GCC (on Linux), i.e. g++ command, you could run it as g++ -H to understand what headers are included, and you should add appropriate -I options to give relevant include directories.
Maybe you just need to add e.g. -I /usr/local/include
You might need to add the developer package of your libraries. (e.g. some libfoo-dev package on Debian or Ubuntu)
In practice, you'll better edit some variable in your Makefile, perhaps some CXXFLAGS

The message you are seeing is during compilation, not running the program. You need to add the concert and cplex include directories to your include path. The examples are in the directory
<cplex_root_dir>/cplex/examples/src/cpp/
The include files are in
<cplex_root_dir>/cplex/include
<cplex_root_dir>/concert/include

The problem occurs maybe because you have installed a 32bit version of IBM ILOG CPLEX Optimization Studio on a 64bit Windows. So Visual Studio can't find related header files like "ilcplex".

Related

Problems Including GTK for C++ on Manjaro Linux

I've been struggling for hours to include the GTK library for manjaro in C++. I'm using VS Code, I have installed the GTK-4.0 package with the command sudo pacman -Syu gtk4 and I'm including the file /usr/include/gtk-4.0/gtk/gtk.h in my C++ program with the line #include <gtk-4.0/gtk/gtk.h>. It's throwing the error
gtk/css/gtkcss.h: No such file or directory
even though there is a file named gtkcss.h at the path /usr/include/gtk-4.0/gtk/css/gtkcss.h
I've looked all over google and I can't find anyone having the same problem, especially on the same OS. Any help is much appreciated!
You are missing an include path.
Gtk requires* pkg-config to set the include path. see https://developer.gnome.org/gtk4/unstable/gtk-compiling.html
So while you have included it with a complete path, the files inside the library still require the include path to be set.
I don't know which build system you are using, but in general gtk requires something like:
g++ $(pkg-config --cflags) -c main.cpp
This will expand to the right flags to set the include path.
*You might also do this manually by adding a -I flag. But that is prone to break if you want to compile on a different machine.

Setting up NLOpt when working from windows cmd prompt

I am writing a c++ program from the windows cmd prompt, and compiling with mingw (g++). This program needs a non-linear optimiser and NLOpt looks like a good choice. I learnt c++ for a uni course, so the environment I was using was already set up, I have no experience in setting up libraries etc.
So far my steps have been;
Download the precompiled DLLs for 64-bit windows (which is what I'm running) from here.
Run the command dlltool --input-def libnlopt-0.def --dllname libnlopt-0.dll --output-lib libnlopt-0.lib (from the same page), which ran without errors.
This creates an .hpp file, however, when I try to #include the file I get
In file included from optimiseDogs.cc:9:0:
C:\Files|Development\NLOpt2.4.2\nlopt.hpp:29:19: fatal error: nlopt.h: Nosuch file or directory
#include <nlopt.h>
nlopt.h and nlopt.hpp are in the same directory as each other. My program is in a different folder.
This is probably really basic, sorry to trouble you with it. Perhaps I am not completely alone in my ignorance and this will help someone else too. Also, I have seen this question, but it deals with installing on visual basic, and I'm not using a GUI, just notepad++ and the cmd prompt.
Thank you for your help.
If you are in windows and using mingw: downloaded zip archive already contains .dll and .lib files. So you dont need to run dlltool which creates these .lib,.dll from .def. I think your problem is compiling command using g++ adding include and library path directives.
C:\Files\Development\NLOpt2.4.2>g++ <path_of_source>.cc -o program.exe -L. -lnlopt -lm -I. -I<path_of_your_headers>
I encounted in the past that order of -I and -L may matter so try changing if not working.
Please see this tut and that tut to understand the concept.

Customize compiler command in C++ IDEs

Is it possible to customize or specify the command for compiling in codeblocks or any of the other IDEs like NetBeans and Eclipse C++?
I'm asking this because I tried all those IDEs and no one can find the libraries even though it's there listed in the code assistance list (NetBeans 7.2). However, when I compile it in shell in Ubuntu 12.04 LTS, the libraries are located and the program can be compiled.
I use one of the commands:
gcc -lGL -lglut filetoCompile.cpp -o compiled.sh
g++ -lGL -lglut filetoCompile.cpp -o compiled.sh
to compile. I'm trying to use glut for open GL stuff and this is the library it can't find. I assume it may be the same for other third party libraries I may add in the future that's why I really need to get this fixed that's why my plan is to have the IDE use that command instead because it might work.
What's also odd is that my /usr/local/lib directory only contains 2 folders: python 2.7 and python 3.2. I'm not sure if this has an effect but is this normal? Shouldn't the libraries somehow be found here and the headers are in /usr/local/include?
The header files are located in /usr/include. Is this the correct location?
Generally speaking, yes this is possible.
In Eclipse CDT, you can set the directory where the header files are in this window:
Right click on project name; Properties; C/C++ General; Paths and symbols; Includes;
In window you must add all directories that contain header files for the functions/classes you want auto completion for. For example, my configuration is:
/usr/include/c++/4.4.5
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include
to find which folder contain an header file you can use the find or locate command, and set the IDE properly.

How to tell C++ library path in Cygwin and MinGW

I develop C++ programs using a Cygwin installation on top of Windows XP.
I also have MinGW installed, because I want to use it's version of g++, not the one that comes with Cygwin.
That part seems to be set up correctly. When I start a Cygwin session I see this:
$ which g++
/cygdrive/c/MinGW/bin/g++
This is correct, g++ is pointing to my MinGW install.
What I don't understand is when I write code that includes library code (for example, header files from the `Winsock/BerkleySockets API), how can I tell where the compiler is finding that header file?
For example, if I have #include "winsock.h" in my code, where does the compiler find that header file?
If I do a general search for winsock.h on my computer, I get this:
C:\MinGW\include
C:\cygwin\usr\include\w32api
Both have a copy of winsock.h (though the file sizes of these aren't exactly the same, so they can't be identical).
Thanks for the help.
I should also point out, I have the C:\MinGW\bin in my Windows PATH Environment Variable, as well as that same path configured in my/etc/profile file within Cygwin.
I'm guessing the g++ compiled for MingW has the same command line arguments as the standard g++. Check out the g++ manual page.
To add include paths to your compilation, use the -I flag.
g++ -I/include/path/here -I/another/include/path -o prog src.cpp
To add library paths to your linking, use the -L flag.
g++ -L/lib/path/here -L/another/lib/path -o prog src.cpp
The MingW site explains how the include file search works on MingW, and how to modify it.
The site also says that if you want to view the include file search while it happens during the compilation, pass the verbose flag (-v) to the compiler.
g++ -v -o prog src.cpp
I believe it's referring to the one in MinGW/include. Take a look at the Minigw documentation for include paths.
If you are using an eclipse environment you can specify the include paths in the project settings along with specifying your choice of compiler i.e mingw in your case. Let us know if you still have a problem.

Listing/setting directories that make & C++ search for header files

I have a project with which I'm learning how to use make with C++ (which I'm also learning).
I've managed to get GCC 4.6 installed with mac ports, and have installed the Boost libraries with homebrew.
My issue now is that my project's includes to boost aren't working with this error:
fatal error: boost/test/unit_test.hpp:
No such file or directory
I guess the version of GCC I'm using (the one installed by mac ports) is not using the standard search path for include files? The file in question (boost/test/unit_test.hpp) is definitely on my system, at /usr/local/include.
Is there some way that I can list the directories that are being searched in make & by GCC, so that I can verify that this is indeed the problem?
Cheers for any & all help,
Doug.
gcc -v -x c -c /dev/null
will give you, among other things, the path used for searching include files. You can modify this path with arguments to gcc. The main one being -I/another/path/to/use but you may want to read the gcc documentation.