g++ #include file not found compiler error - c++

I'm currently trying to simply link a file called main.cpp with boost in order to do asio(asynchronous input and output). I'm using a makefile in order to compile the C++ code into executable form. However, despite using the -I modifier on my terminal command in Mac OS X, it still cannot find the appropriate directory to search in. Here is my code in Main
#include <asio.hpp>
int main(){
return 1;
}
and here is the makefile command that I am using
all:
g++ -Iboost_1_60_0/boost/ -o main main.cpp
In my file structure, boost_1_60_0, main.cpp, and makefile are all on the top level, where asio is in the folder boost which is in the folder boost_1_60_0. I'm very confused about this and any help would be appreciated! Thanks!
EDIT: Full error is
1 error generated.
make: *** [all] Error 1
iMats-2:SerialC++ wfehrnstrom$ make
g++ -Iboost_1_60_0 -o main main.cpp
main.cpp:2:10: fatal error: 'asio.hpp' file not found

You should use -Iboost_1_60_0 (or, better still, install Boost properly so that it's found automatically under /usr/include/), and write #include <boost/asio.hpp>.
The include directives inside Boost itself will assume this form, so…
BTW, this has nothing to do with exceptions. Presumably it's a compiler error you've seen.

Related

Can't build SSDL from the source code of the book C++ for the Lazy Programmers

I can't compile the SSDL source code from the book C++ for the Lazy Programmers (2019) by Will Briggs on my ubuntu 20x so could you please tell me what goes wrong? I installed SDL2 and it's working but most of the cases I get the following error when I compile an SSDL code;
cpp-for-lazy-programmers/ch1/hello$ make -f Makefile.unix
g++ -c -g sdl2-config --cflags -I…/…/external/SSDL/include main.cpp -o main.o
In file included from …/…/external/SSDL/include/SSDL.h:27,
from main.cpp:7:
…/…/external/SSDL/include/SSDL_display.h:28:10: fatal error: SDL_ttf.h: No such file or directory
28 | #include <SDL_ttf.h>
| ^~~~~~~~~~~
compilation terminated.
make: *** [Makefile.unix:60: main.o] Error 1
I just can't understand why SDL_ttf is a big issue as I see many posts regards to SDL_ttf?
Just because they both have "SDL" in the name does not mean they are part of the same library.
If you search for SDL_ttf.h on packages.ubuntu.com ("contents of packages"), it will tell you that you want the libsdl2-ttf-dev package
This is also mentioned in the accompanying documentation.

Issue with building makefile

I am trying to build a simple makefile for c++ using g++. Even a simple makefile is not working on my computer (MacOS X).
I followed this tutorial
Create the same files and makefile. I just replaced CC=gcc to CXX=g++, in makefile2. I am using c++ format for files.
I can compile it with g++, (in command line)
But when I try to make it by "make" command I get the following error.
make: *** No targets specified and no makefile found. Stop.
Format and directory are correct.
Any help is appreciated.
Here is makefile:
CXX=g++
CFLAGS=-I.
hellomake: hellomake.o hellofunc.o
$(CXX) -o hellomake hellomake.o hellofunc.o
"hellomake.cpp" :
#include "hellomake.h"
int main() {
// call a function in another file
myPrintHelloMake();
return(0);
}
hellofunc.cpp
#include <stdio.h>
#include "hellomake.h"
void myPrintHelloMake(void) {
printf("Hello makefiles!\n");
return;
}
hellomake.h
/*
example include file
*/
void myPrintHelloMake(void);
The issue was about makefile format. Initially it was makefile.rtf. Following comments I changed it to plain text (No extension) and the issue solved.

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 ...

"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.

Using MTL/Boost Library Mac Terminal C++

To be precise, I'm attempting to run this excellent project: https://github.com/ppwwyyxx/panorama
I'm using a modern mac.
The issue is that I can't seem to get my computer to properly include the MTL library. I'm stuck with the endless error of:
$ make
[cc] matrix.cc ...
matrix.cc:5:10: fatal error: 'boost/numeric/mtl/mtl.hpp' file not found
#include <boost/numeric/mtl/mtl.hpp>
^
1 error generated.
make: *** [obj/matrix.o] Error 1
I've tried cmake. I've downloaded both the boost and mtl4 libraries. I've put them in my /usr/local/include directory. Nothing seems to be working.
Any advice would be excellent, thank you!
Try to modify the Makefile in src and add this on the line 7 of the Makefile:
-I/usr/local/include