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.
Related
I tried to run a c++ file with the mac terminal, but it gave me the error as shown below:
Does anyone have any idea why this is happening?
If you do this gcc test.cpp you will get executable called a.out, and to run it you type:
./a.out
to get executable called test you have to run g++ test.cpp -o test now you can run this:
./test
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 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.
I've written a program, saved it on the desktop under the name 'Swap.cpp' and when I run gdb (the first time), I get the error:
"/Users/myname/Desktop/Swap": not in executable format: File format
not recognized.
I have no idea what I'm doing wrong. Any help will be appreciated.
Sorry I should've given more information:
I am using Mac OS.
I've already compiled the program and have the Swap.o file that I can see on my desktop.And here are the commands that I enter while trying to run the debugger from bash:
$ clang++ -g Swap.cpp -o Swap
$ ./Swap
this runs Swap and then I try to access the debugger using:
$ gdb Swap
that then gives me the aforesaid message. I tried doing what Rakholiya Jenish suggested but to no avail.
To run gdb on windows:
path_to_gdb.exe program_to_debug
If the compilation was not proper, either compile it with your IDE (if you are using) or with g++ using cmd.exe as:
g++ -g Swap.cpp -o output -lm
I figured out how to use lldb instead of gdb. lldb works just fine. Here is what I did:
$ clang++ -g -o Swap Swap.cpp
$ lldb Swap
Thank you all for your help.
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