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
Related
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.
This is my first go at making my own header file. I am trying to make a simple Hello World program in C++ on Ubuntu. made 3 files as follows :
//hello.h file
#ifndef HELLO_H
#define HELLO_H
//my own code
void hello();
#endif
//hello.cpp file
#include <iostream>
#include "hello.h"
using namespace std;
void hello()
{
cout << "This line is printed from header.";
}
//main.cpp file
#include <iostream>
#include "hello.h"
using namespace std;
int main()
{
cout << "in main" << endl << endl;
hello();
return 0;
}
I've tried
g++ -I /home/Desktop/hello/ -c hello.cpp -o hello.o
to compile header file and this command worked.
then, while doing
g++ -o main main.cpp
I am ending up with following error:
/tmp/ccb0DwHP.o: In function `main':
main.cpp:(.text+0x2e): undefined reference to `hello()'
collect2: error: ld returned 1 exit status
Please suggest whether changes need to be made in any file or in any command in the terminal?
thank you
You don't link to hello.o in the command below:
g++ -o main main.cpp
Try this:
g++ -o main main.cpp hello.o
Or for such simple program, just issue the command below:
g++ -o main main.cpp hello.cpp
For ease of use, create a makefile, then you just run make:
make
A simple makefile:
helloprogram: hello.h hello.cpp main.cpp
g++ -o helloprogram main.cpp hello.cpp
clean:
rm helloprogram
Put hello.h in Path2Hello;
g++ -o main -I Path2Hello main.cpp hello.cpp
ps: -I option to specify an alternate include directory (for header files).
To compile and run a C language program, you need a C compiler. To setup a C language compiler in your Computer/laptop, there are two ways:
Download a full fledged IDE like Turbo C or Microsoft Visual C++, which comes along with a C language compiler.
Or, you use any text editor to edit the program files and download the C compiler separately.
So I have been trying to install DDD. I am on a Mac OS X 10.9(Mavericks) and I have the latest Xcode installed. Whenever I run my configure file the last thing I get is the following:
checking whether c++ accepts -g... yes
checking whether the C++ compiler (c++) compiles a simple program... no
configure: error: You must set the environment variable CXX to a working
C++ compiler. Also check the CXXFLAGS settings.
See the file 'config.log' for further diagnostics.
and whenever I check the config.log file I get:
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
configure:2678:10: fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
configure: failed program was:
#line 2677 "configure"
#include "confdefs.h"
#include <iostream.h>
int main() {
cout << "hello, world!";
; return 0; }
I have downloaded the gcc from sourcefourge and installed gcc-4.9 again, but I still getting the same error. Anybody knows how to fix this or what the problem maybe?
It seems like you are compiling c++ program but you passing .c file to c++ compiler. You passing conftest.c file to c++ compiler, it has to be confest.cpp.
configure:2684: c++ -o conftest -g -O2 conftest.C 1>&5
This has to be
configure:2684: c++ -o conftest -g -O2 conftest.cpp 1>&5
And
fatal error: 'iostream.h' file not found #include <iostream.h>
1 error generated.
For above error change your code
to #included <iostream>
instead of #include <iostream.h>
Just open you configure file in DDD directory and add the following
`<iostream>
using namespace std;
`
and that should solve this error
when compile with g++ -std=c++0x -Wall test.cc -o hello,
output fatal error: cstdatomic No such file or directly
Where is missing?
The include should be #include <atomic>