Sunday, June 2, 2013

C++ No new line at end of file

This happened when I was moving a project from Microsoft visual studio to a linux machine.

When I ran g++ or even gcc for that matter, I got a bunch of errors:
In file included from Game.cpp:13:
treasure.h:22:7: warning: no newline at end of file
item.cpp:17:2: warning: no newline at end of file
player.cpp:66:2: warning: no newline at end of file
In file included from potion.cpp:5:
potion.h:17:7: warning: no newline at end of file
potion.cpp:21:2: warning: no newline at end of file
The reason for this problem is the studio editor did not seem to insert a new line at the end of the file and older c++ compilers require this line to delimit where the header file ends when including it.

I got around this problem by:
[test_comp53]$ for f in *.cpp; do echo "" >> $f; done
[test_comp53]$ for f in *.h; do echo "" >> $f; done

0 comments:

Post a Comment