Professor's code not compiling (#include cannot find file in the same directory as main.cpp)

My professor gave us the solution to the assignment after we did it but I can't compile it (Running `g++ -std=c++11 main.cpp` I get error shown here: http://imagizer.imageshack.com/img924/2128/v0xgnV.png).

Last edited on
Considering that it gives you an error in line 112, but your main.cpp has only 107 lines, I'll say that that is not the code that you are compilling.


> g++ -std=c++11 main.cpp
http://www.cplusplus.com/forum/general/113904/#msg622055
Nothing else but some comments were removed to reduce clutter. Anybody able to compile it on their machine?
Last edited on
You're not compiling one of the files. I see your have main.cpp in your compilation command, but not gettoken.cpp

g++ -std=c++11 main.cpp gettoken.cpp
It builds fine.

> Nothing else but some comments were removed to reduce clutter.
but rendering the testcase useless because the line numbers are incorrect.


#include "folder/include" will give you
fatal error: folder/include: No such file or directory
I did `g++ -std=c++11 main.cpp gettoken.cpp` but I'm still getting the same error.

@ne555 Sorry, what did you mean? What did you add to the posted code that would make it compile without errors? This is my first C++ class, please forgive me.
Last edited on
Nothing. I had main.cpp, gettoken.cpp and the header file sitting next to each other and I typed that command. It compiled fine.

I have no idea what error you're getting because the link doesn't work. There's no image there.
Sorry, this is the image: http://imagizer.imageshack.com/img923/8886/brENth.png

I copied the code from my original post into a clean folder and ran g++ -std=c++11 main.cpp gettoken.cpp and got that. All 3 files are directly under that folder. Thank you for your patience.
Last edited on
Try doing it all in directories without spaces in the names.
Well it's nothing to do with the code above. I have no idea where it's getting the idea that there is a location named "folder/include"
Ok, I just tried it on the school system (Linux)--g++ -std=c++11 main.cpp gettoken.cpp results in an unrecognized command line option error while g++ -std=c++0x main.cpp gettoken.cpp compiles.

Both commands result in the error mentioned earlier on my Windows machine. This is so bizarre, still trying to figure out what's the problem because I need to code and compile on the Windows machine but at least I can compile. Maybe I need to get a new compiler... Thank you anyway.
As an aside, sounds like your school system should think about getting a more recent version. The first version of the GCC that recognised -std=c++11 was 4.7, exactly four years ago (March 2012), so what you've got there is something older than that.
Last edited on
@immortal192

As another hopefully useful aside, always compile with a high level of warnings, as a minimum use -Wall -Wextra -pedantic-errors and optionally (but useful) those extra ones that I mention here:

http://www.cplusplus.com/forum/beginner/186236/#msg908299

Note that I mention the latest standard being c++14, you could substitute in the latest one that a compiler supports, as in -std=c++0x on your school system. I also mention clang++, but that is generally very similar to g++.

Here is a description of the extra ones, which I copied from the gcc5.3 manual:

http://www.cplusplus.com/forum/general/183731/#msg899203

https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/

A lot of those warning options have been around a long time, they should still work on the older compilers. If in doubt read the manual for the particular version of compiler being used. The gcc web page has complete and separate documentation for each distinct version.

IMO clang is slightly better than gcc, consider getting it yourself - AFAIK it can be integrated into IDE's on Windows. It might be worth mentioning it to your school too - hopefully not too much of a drama to install it, and it's free. To install directly, it might need a fairly recent version of Linux - something less than 3 versions old. In any case I am sure the sys admins would hopefully be all over that.

http://llvm.org/

Good Luck !!

Last edited on
Thanks for all the information guys, will check it out.
Last edited on
Yup, turns out installing MinGW's 64-bit variant (the provider of this 64-bit variant continues to develop MinGW, as opposed to the provider of the 32-bit variant whose development has stopped a few years ago) fixed it. Also, I read that clang compiles code noticeably faster than gcc in general and gcc tends to optimize the code marginally better on some occasions. For my purposes, seems like clang is the best choice--gcc can still be used to optimize the code for the finished product.

Thanks all.
Topic archived. No new replies allowed.