I keep getting this error when I try to compile a .cpp file in my unix terminal.
Here is my command:
-bash-4.2$ g++ -o test.cpp test
Output:
g++: error: test: No such file or directory
g++: fatal error: no input files
compilation terminated.
But, when I type in ls:
test.cpp
Do I have the wrong version of g++?
Your command line is wrong. Try this
g++ -o test test.cpp
The syntax is -o <output-file>, but you had your input file listed there, so g++ was looking for test as an input file.
Related
I'm a begginer in programming and new to everything.
I am trying to use the Mac terminal to run my C++ program. My file name is Learning and my executable file is main.cpp.
I've tried:
$ g++ -o Learning main.cpp
$ ./main
But when I command the first line it returns:
clang: error: no such file or directory: 'main.cpp'
clang: error: no input files
This gives me the error message so I tried another way:
$ g++ main.cpp
$ ./a.out main.cpp
But it still gives me the same error message. I'm lost.
Does anyone have any anwsers?
P.S. Thanks for taking the time to read this and potentially help me.
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.
I'm trying to compile on linux mint shell the following cpp file:
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello"<<endl;
return 0;
}
the most basic program possible since I just wanted to test compiling on shell
I tiped:
g++ -o hello.cpp hello
and as a result:
g++: error: hello: no such file or directory
g++: fatal error: no imput files
compilation terminated
what did I do wrong?
It's:
g++ -o hello hello.cpp
The -o indicates the desired name of the output file
When I try to compile C++ programm in Code::blocks it gives me this error:
-------------- Build: Debug in elcounter (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Weffc++ -Wall -std=c++14 -fexceptions -Weffc++ -std=c++14 -g -I"C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\" -c "C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
mingw32-g++.exe: fatal error: no input files
I am using MinGW g++ compiler.
Just for a test, I tried to compile simple "Hello, world" file and it gave me the same error.
Compiled the same "Hello, world" file in a command line using
"g++ test.cpp -o hello.exe" and in worked just fine, so I believe the compiler is installed correctly.
The error seems to be related to spaces in a file path.
C:\Users\Zahir\Box Sync\CPP projects\September_2k16\elcounter\
mingw32-g++.exe: error: Sync\CPP: No such file or directory
mingw32-g++.exe: error: projects\September_2k16\elcounter\main.cpp -o obj\Debug\main.o: No such file or directory
Might be a problem with a build system in Code::blocks? I tried to copy the command code::blocks using to a command line and it gave the same error. (mingw32-g++.exe -Weffc++ -Wall etc.)
EDIT: I don't want to change file path because "Box Sync" is used by the same name app that synchronizes file with a cloud.(box.com) The app doesn't support changing the main folders name and I'd prefer the project files stay synchronized.
Looks like you need to remove all spaces from file and folder names in your project.
In your case it's the 'CPP projects' folder and 'box sync'
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