g++ -I and -L commands to find .hpp files not working - c++

So I am trying to compile a file (main.cpp) that has
#include <SFML/Graphics.hpp>
My main.cpp file is in the directory:
~/"Documents/16_Games/01 Tetris/main.cpp"
The Graphics.hpp file is in the directory:
/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML
The error I am receiving is:
/Users/linsu/Documents/16_Games/01 Tetris/main.cpp:1:10: fatal error: 'SFML/Graphics.hpp' file not found
#include <SFML/Graphics.hpp>
^~~~~~~~~~~~~~~~~~~
1 error generated.
Some commands I've tried include:
g++ -I /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
g++ -L /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML -I /Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML ~/"Documents/16_Games/01 Tetris/main.cpp"
All of them throw the same error; I feel dumb. Am I missing something?

The compiler will only search through the exact path you provided, not through the whole chain of subdirectories. It appends the name you provided (SFML/Graphics.hpp) to all the paths it can look for.
It looks in all the system header locations, in current directory (./SFML/Graphics.hpp) and for a concatenation of path provided with -I and filename provided by the programmer:
/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include/SFML/SFML/Graphics.hpp
Since none of these locations contains such file, compiler fails.
You want:
g++ -I/Users/linsu/Documents/libcpp/SFML-2.5.1-macos-clang/include ~/"Documents/16_Games/01 Tetris/main.cpp"
Notice that SFML directory is not in the -I option, because it's provided already in your code.

Related

vscode does not recognize terminal command ''make''

I created a make file to run a sdl2 window
Make file
all:
g++ -I src/include -L src/lib -o main.cpp -lmingw32 -lSDL2main -lSDL2
Opened a new terminal and the command ''make'' doesn't create my .exe file, it isn't really recognized at all
is there an easier way to use the cmd terminal to create an .exe file with sdl2?
I tried going the cmd path : g++ -o main main.cpp
and the result was:
main.cpp:2:10: fatal error: SDL2/SDL.h: No such file or directory
2 | #include <SDL2/SDL.h>
| ^~~~~~~~~~~~
compilation terminated.
So apparently the problem is that my file doesn't include SDL.h even tho it is present in the SDL folder.
Also cmd straight out deleted my ''main.cpp' file.
Also tried mingw32-make in the terminal and it also deleted my main.cpp file and found the same errors.

G++ compiler not recognizing SQLAPI.h header file

I'm trying to compile a C++ program on my MacBook CLI using:
g++ -o -I/Users/user/SQLAPI/include/SQLAPI.h program driver.cpp
but getting the error:
driver.cpp:3:10: fatal error: 'SQLAPI.h' file not found
#include <SQLAPI.h>
^~~~~~~~~~
I placed the download from https://www.sqlapi.com/Download/ into directory /Users/user/SQLAPI/. I've confirmed that the SQLAPI.h file is in /Users/user/SQLAPI/include/SQLAPI.h, so I'm confused as to why my g++ isn't recognizing the header file. Please help!
The argument for -I is the directory to search for the headers.
The argument for -o is the output file name.
You most probably want to:
g++ -I /Users/user/SQLAPI/include -o program driver.cpp
Which of course most probably will solve only the current include problem and will not link with SQLAPI library.

the g++ command returns no such file or directory

I am new to programming; I'm starting a new job and I have to resume what the fellow before me did.
So I have to run a program called test.cpp in C++. This code contains a header called misc.hpp located in a subfolder of where test.cpp is called include.
When I open the terminal from where test.cpp is and run g++ test.cpp it tells me that:
test.cpp:4:19: fatal error: misc.hpp: No such file or directory.
I also tried the g++ test.cpp -I include/misc.cpp but same thing
Could you please help me?
The -I (upper-case i) option is to add a directory to search for header files. It's not for including source files.
So if the header file is include/misc.hpp then you should do
g++ test.cpp -Iinclude
-I include/misc.cpp doesn't work because:
The file is misc.hpp, not misc.cpp
You do not include files like this
-I is for include directories
So:
g++ test.cpp -I include

gcc how to include multiple header file at compile time for shared object

I am trying to compile a .so file from a .a file and a .h file and a source file
.cpp
.so-output, shared library
.a-static library to use
.h-header file for the API
.cpp-source file
/include - Python dev package headers
When I first tried
gcc -fPIC pyOkHound.cpp -L ./PhraseSpotterAPI.h ./libPhraseSpotter.a -shared -o OkHound.so
gcc throws pyOkHound.cpp:4:20: fatal error: Python.h: No such file or directory
compilation terminated.
which make sense because my source file needs Python.h
Then when I include the python lib
gcc -fPIC pyOkHound.cpp -L ./include/*.* ./PhraseSpotterAPI.h ./libPhraseSpotter.a -shared -o OkHound.so
it throws
gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.
I tried -l and -L to include the header files from python dev but it throws the same thing.
However I do not think the -include is the right one to use since the header file is for the API not the source code.
how to include multiple header file at compile time for shared object?
I follow the -I flag also here https://www.rapidtables.com/code/linux/gcc/gcc-i.html
gcc -c -fPIC pyOkHound.cpp -I./include -shared -o OkHound.so

Compile c++ file using external library from linux terminal

I have the following files:
ex1.cpp ex1.h
GLee.cpp GLee.h
and I want to make it use the library (openmesh library) on the following path:
home/xyz/Downloads/OpenMesh-2.3/src/OpenMesh/
I'm trying to execute it with this:
g++ -Wall -o ex1 ex1.cpp GLee.cpp -L/..path../
but no luck, output is:
In file included from ex1.cpp:17:0:
ex1.h:28:38: fatal error: OpenMesh/Core/IO/MeshIO.hh: No such file or directory
compilation terminated.
what is the correct way of doing this?
Thanks!
You need to put -I path on the command line. So from the error, it looks like you would do:
g++ -Wall -o ex1 ex1.cpp GLee.cpp -I /home/xyz/Downloads/OpenMesh-2.3/src