gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > How to compile cpp

#130851 - gyokimae - Fri Jun 08, 2007 6:41 pm

I've got my devKitPro up and running and have been enjoying it for a few days.

As I am not fluent in reading the make file, I would appreciate advise on how make differentiates which file to search.

As far as I see in the makefile, it appears to me as if a scan is done to find every .c, .cpp and .s files found.

However, for example when I rename main.cpp to main.c in Graphics/2D/hello_world, it returns the following error.

make[1]: *** No rule to make target `c:/devkitPro/examples/nds/Graphics/2D/hello_world/source/main.cpp', needed by `main.o'. Stop.


I would like to know as I have some background building classes and other languages and would like to know how to utilize the templates to run c++ code.

Thank you.

#130852 - keldon - Fri Jun 08, 2007 6:51 pm

http://www.eng.hawaii.edu/Tutor/Make/
^^ a simple explanation of what goes on in Make. It contains what some would call bad practises or errors but it is great at introducing newcomers by letting them know what a makefile is and what exactly goes on.

#130854 - gyokimae - Fri Jun 08, 2007 7:04 pm

keldon,

Thank you for the link.
A while back I have breifly read through O'Reilley's book on GNU make and I believe I have a vague idea of the process.
I've also ran a review through the site you have introduced me but yet not clear with this particular problem.

I would appreciate some pointers to specific lines that allow main.cpp to compile, and yet refuse main.c to work in the hello_world example attached libnds.

Thank you.

#130866 - Cearn - Fri Jun 08, 2007 8:43 pm

The problem is that the header dependency files (inside the build folder) are still using the old names. In this case:
Code:
# in build/main.d
main.o:  \
 e:/dev/devkitPro/examples/nds/Graphics/2D/hello_world/source/main.cpp \
  e:/dev/devkitPro/libnds/include/nds.h \
  e:/dev/devkitPro/libnds/include/nds/jtypes.h \
  e:/dev/devkitPro/libnds/include/nds/bios.h \
etc...

The filelist in the makefile is updated automatically, but those in the dependencies aren't. To fix, remove the offending .d files, either manually or via make clean. Note that this relates to filename changes, not C vs C++.

#130879 - gyokimae - Fri Jun 08, 2007 11:25 pm

Cearn,


Ah, of course!
I have wondered why the comment implied

main.cpp', needed by `main.o'

ut I had no idea why and that explained it all!

Thanks again to keldon also. Never have felt so releaved.