I just tried to compile simple Hello World in C++ using MinGW compiler in my Windows 10 command line. I used the command gcc main.cpp, and as I hit enter, I got this error: 'main.cpp:1: No include path in which to find iostream'.
What is the error and how do I fix it?
Use g++ main.cpp
The command gcc is setup for c compilation. It does not link the c++ standard library.
g++ does link c++ standard library.
Related
I'm on Mac OS. I'm using Visual Studio Code.
I'm coding in C++. I recently installed the most recent version of Boost (1.76.0).
My file name: test.cpp
I've included this header in my file:
#include <boost/smart_ptr/scoped_ptr.hpp>
I'm compiling with this command:
g++ -std=c++11 test.cpp
My code won't compile. I keep getting this error:
'boost/smart_ptr/scoped_ptr.hpp' file not found
Question: What am I doing wrong?
Any help is greatly appreciated.
It's simple, whenever you use g++, you need to define your include folders with -I switch, in this case you can say:
g++ -Iboost -std=c++11 test.cpp
here boost is the name of the folder that your .h/.hpp files are inside it.
Update
Here is also a link that completely explain about how to use boost library: Link
I was trying to include the GMP library, which was simply the code below(I did nothing else):
#include <gmpxx.h>
However, when I tried to compile the code, the following error from g++ compiler occured:
myCode.cpp:3:10: fatal error: gmpxx.h: No such file or directory
#include <gmpxx.h>
^~~~~~~~~~~~~~~~~~~~~~
I have tried everything I searched online, putting the GMP lib here and there, adding INFINITE includepaths in c_cpp_properties.json, still, it keeps showing the message, although, I can find the file through "Go to Definition" option.
Is there any known solution to this?
It's not enough to configure VS Code includes, you need to pass those options to the compiler as well.
You don't mention your platform at all, so I'm going to use an example from my personal machine, a Macbook Pro with the fmt library.
When compiling with the fmt library, I have to provide three more options to the compiler.
-I/usr/local/include // Tells the compiler where to look for extra includes
-L/usr/local/lib // Tells the compiler where to look for extra libraries
-lfmt // fmt-specific command to use fmt library
So the full command ends up looking like this:
g++ -Wall -std=c++17 -I/user/local/include -L/usr/local/lib -lfmt main.cpp
I need all three options because fmt is installed in a non-standard location that the compiler doesn't check by default. According to the documentation, you can get away with just -lgmp and -lgmpxx if you installed the library in a standard location (happens by default with *nix and a package manager, I imagine).
If you use build tasks in VS Code, this can be set up and automated for you.
I can't build this simple program on cygwin:
#include <nan.h>
int main(){}
I get this error message:
$ g++ a.cpp
a.cpp:1:17: fatal error: nan.h: No such file or directory
compilation terminated.
Is it possible to install something on cygwin to get correct nan.h?
nan.h is an obsolete include of old gcc. On Cygwin NAN is defined on math.h
You can not use a software written in 2008
https://boutell.com/fracster-src/doubledouble/doubledouble.html
for such specific issue and just hope than it works out of the box.
You need to figure out where nan.h is located and than Add this path to the includes.
How to make g++ search for header files in a specific directory?
I was trying to figure out how to link Fortran and C++ code, and one of the tutorials had written 2 programs, one in C++ in a file named testC.cpp, and the other in Fortran in a file named testF.f but I need to input the following compilation instructions:
gfortran -c testF.f
g++ -c testC.cpp
g++ -o test testF.o testC.o -lg2c
Problem is, I'm working in an IDE called Bloodshed Dev-C++ so I have no idea how to do this. I tried going in compiler options and in the general section I appended those instructions in the option "add the following commands when calling the compiler". Doesn't work.
Maybee you need use custom Makefile. Project->project options. Or include *.mak files
I want to compile a C++ program with a twitter library, on Linux.
I'm current using twitcurl as the twitter API library and installed g++ and all the necessary files and packages that are listed on the official website: http://code.google.com/p/twitcurl/wiki/WikiHowToUseTwitcurlLibrary
However, when I compile my program using this command g++ twitterClient.cpp -ltwitcurl, I get this error: cannot find -ltwitcurl
I also used CodeBlocks IDE to compile it but got this error: undefined reference to twitCurl::~twitCurl()
`
My code only contains a few lines:
#include <iostream>
#include "Twitter/Twitter.hpp"
using namespace std ;
int main ()
{
Twitter t ;
return 0 ;
}
I've already spent a lot of time on this but am unable to solve the problem. What should I do in order to compile the program on the command-line and CodeBlocks?
$ g++ twitterClient.cpp -ltwitcurl
cannot find -ltwitcurl
This means your compiler doesn't find the libtwitcurl.so.1. in its library directories.
First, make sure you correctly build the twitcurl library and obtained the libtwitcurl.so.1. file with something like this :
svn co http://twitcurl.googlecode.com/svn/trunk/libtwitcurl
cd libtwitcurl/
make
Secondly, make sure you put the file (or a symlink) in one of your compiler's library path :
cp libtwitcurl.so.1.0 /usr/lib/
You can check g++ library paths using the following command :
g++ --print-search-dirs | grep libraries
(/usr/lib/ is usually at the end.)
If you don't want/can't put the file in your compiler's library path, you can also tell it where to find libtwitcurl.so.1. by adding -L/path/to/twitcurl/ in the g++ options, but it is not needed if the file is already in one of the compiler's library path.
You need to specify path to twitter lib:
g++ twitterClient.cpp -L/path/to/lib/dir -ltwitcurl