How to run a .cpp file with Gecode Framework on Linux? - c++

I use Ubuntu 18.04 and try to compile the example 'money.cpp' file that Gecode brings. I downloaded (gecode-release-5.1.0.tar.gz) and extract it. Then to install Gecode I do the following steps:
(1) ./configure
(2) make
I get satisfactory installation.
Then I try to compile money.cpp, like this:
$g++ money.cpp
and I get the following error:
fatal error: gecode / driver.hh: No such file or directory
  #include
           ^ ~~~~~~~~~~~~~~~~~
I know the problem is that it does not recognize the libraries, but how can I make my .cpp or compile phase recognize them?
regards!
Alberto

You need to call g++ with the -I flag so that g++ knows where to look for the include files:
g++ -I<dir> money.cpp
<dir> is the source code directory for the files (the one with structure as seen on GitHub):
https://github.com/Gecode/gecode
See Compiling with g++:
https://courses.cs.washington.edu/courses/cse373/99au/unix/g++.html

Related

Error message while compiling a program

I’m a newbie to C++ and Linux. There is this code I’m playing with that requires me to install the HElib (Homomorphic encryption library and other libraries - GMP, NTL) which I did. I want to compile the code (main.cpp) that has a header file (FHE.h) in HElib. My problem is how can I link FHE.h (in HElib folder) and main.cpp (in another folder) together so that I can compile them. I have tried some commands
g++ -I/Home/HElib/src/FHE.h main.cpp -o main
Error message
main.cpp:1:17: fatal error: FHE.h: No such file or directory
compilation terminated.
Another command line
g++ -I/Home/HElib/Src/FHE.h -I/Home/SimpleFHESum-master/SimpleFHESum-master/main.cpp -o main]
Error Message
g++: fatal error: no input files
compilation terminated.
What's wrong and how can I fix this?
The -I flag adds the following directory to the include path of the compiler. This enables you to write e.g. #include "FHE.h" even though that file is not located in the same folder as the source file you're trying to compile.
Have you tried just removing the 'FHE.h' part from your -I directive?
g++ -I/Home/HElib/src ...

Compile C++ code in Ubuntu with gcc linking a library

I'm stuck in a very simple problem: I cannot manage to make work my simple code example in C++.
I want to include the "curl" library but when I compile with the command:
g++ -o myprog.out myprog.cpp -L/curl/include/ -lcurl
I get the following error message:
myprog.cpp:3:71: fatal error: /curl/include/curl/curl.h: No such file
or directory
My folder contains:
myprog.cpp (the file I want to compile)
curl -> include -> curl -> curl.h (path in which the curl.h file is located).
My headers file are configured in this way:
include<iostream>
include<string>
include<curl.h>
What I'm doing wrong? It's probably a very simple problem but it's driving me crazy :-/
Change #include <curl.h> to #include <curl/curl.h>.
Change -L/curl/include/ to -I/curl/include.
Add -L/curl/lib -Wl,-rpath=/curl/lib (or whatever the path to curl built libraries).

"fatal error: boost/regex.hpp: No such file or directory" when trying to compile C++ program using a makefile

I am trying to compile a piece of open source software called "SPECIES
Identification of Taxonomic Mentions in Text". I am on MacOS.
I downloaded the source code (which can be found here), moved into the directory and used the command make to compile. This is the error returned:
g++ -fpic -pthread -Wall -O3 -o organisms organisms.cxx -lm -lboost_regex
In file included from batch_tagger.h:5:0,
from organisms.cxx:3:
tagger.h:7:27: fatal error: boost/regex.hpp: No such file or directory
compilation terminated.
make: *** [organisms] Error 1
I installed the C++ boost library using brew install boostand tried the above steps again (it did not work).
I tried dropping the boost directory into the directory containing the source code (it did not work).
Any suggestions/help?
You need to tell the compiler where to find boost headers.
You need to use the include path option to specify where the boost headers can be find, use -I/path/to/boost/include.
Then include the file using #include <boost/regex.hpp> from your code.

c++ include directory "file not found"

I'm working on getting an example run for the audioCaffe framework http://multimedia-commons.s3-website-us-west-2.amazonaws.com/?prefix=tools/audioCaffe/
The root directory of this project contains an include directory.
Except, when I navigate to tools and compile g++ caffe.cpp it throws an error:
caffe.cpp:8:10: fatal error: 'caffe/caffe.hpp' file not found
note that include/caffe/caffe.hpp exists
Since you mentioned using g++ caffe.cpp I assume you execute this command form where caffe.cpp file is, which is:
audioCaffe/tools/caffe.cpp
The caffe.cpp file uses #include "caffe/caffe.hpp" which is in the include directory:
audioCaffe/include/caffe/caffe.hpp
So you will need to tell the compiler where to find the headers, you do this with the -I option. Compile it with the command:
g++ -I ../include caffe.cpp

Missing header file

I am new to C++ programming and trying to add a library (Yepp) to my cpp file.
I am trying to compile and it says it cannot find a header file from the external library. The external library, yeppp, has a .so file which I placed in a lib folder in the root directory.
I am building with the following command:
clang++ -O3 test.cpp -o test -L lib/ -lyeppp
Here's the error:
test.cpp:7:10: fatal error: 'yepCore.h' file not found
#include <yepCore.h>
You need to tell the compiler where to find the header file. Use the -I option.