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.
Related
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.
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
So, I was following a simple C++ with SDL tutorial for linux but i encounter some errors on my way.
First of all I'm using Geany and i downloaded the corresponding SDL2 libs, here is the thing:
in my project folder there is a main.cxx file, which i open with geany as i mentioned before:
I included this libraries:
#include <iostream>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
First i encountered a pelculiar error, compilation performs sucessfully but when it comes to build i got this error:
main.cxx: undefined reference to `SDL_Init'
After searching a bit i found out that i had to add the tag -lSDL to my geany build options so they would end up being somethinf like this:
Compile:
g++ -Wall -c -lSDL "%f"
Build:
g++ -Wall -o -lSDL "%e" "%f"
But there is a problem, now when I execute the build command i get a:
G ++: error: main: There is no such file or directory
Why am i getting this error, am I including a wrong library or g++ has problems with .cxx files?
I already tried converting between .cxx and .cpp.
Thanks in advance.
g++ -Wall -c -lSDL2 "%f"
There is absolutely no need to specify libraries during compilation phase. Remove -lSDL.
g++ -Wall -o -lSDL2 "%e" "%f"
It invokes compiler, implies linking (no -c or other operation-specific flags), and sets output file name to -lSDL2. That is, linker will output resulting binary in a file named -lSDL2 in current working directory. Then, when it comes what files to link, it goes main, which supposed to be -o main, but since you've broken flags order it is now just ordinary file name that linker will try to link into resulting binary. It so happens that this file doesn't exist.
Long story short, make correct linking line - g++ -o "%e" %f -lSDL2 (libraries comes last, library order is also important).
I wanted to separate function definitions and function headers using folders but I get a fatal error saying "x.h" was not found. The filenames provided below are just samples. Is this even possible?
This is the line I'm using:
g++ -I ./headers/ -o main2.o main2.cpp ./definitions/x.cpp
If you're sure you've correct files in correct path, one issue is :-
There shouldn't be any space after -I and use just ./headers
g++ -I./headers -o main2.o main2.cpp ./definitions/x.cpp
^^No Space
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