header file problem

Ok, I'm a bit embarassed to even ask this, but here goes:

I have a program with one main.cpp file, and a class contained in Foo.h and Foo.cpp. Foo.h contains the declaration of the class. Foo.cpp contains #include "Foo.h", and the implementation of the functions in that class. However, when I #include "Foo.h" in the main.cpp file, the compiler can't find the implementation of the functions. However, this approach works fine whenever I do it in my IDE(XCode), it's only when I use notepad and terminal that this problem arises.

I've been wondering for some time how the compiler knows which .cpp-file accompanies a .h-file, so if someone out there could bear with me and explain to me what I'm doing wrong, it would be greatly appreciated;)

Fafner
closed account (S6k9GNh0)
Have you tried using something that doesn't suck ass like notepad?

I suggest Notepad++. It's probably a better way to go.
closed account (1yR4jE8b)
If you are compiling on the command line are you including all of the .cpp files in the command?

g++ main.cpp Foo.cpp
I'm sorry, I should have said that I use smultron, not notepad.
GCC is slippery for multi-file processing at best.

EDIT: what darkestfright said should work.

-Albatross

P.S.- Isn't Mac one of the most terrible platforms to develop for if you're using C++? :P
Last edited on
darkestfright: that sovled it, thanks;) still new to c++;)

Albatross: I haven't found anything to be wrong with it yet, how come?
closed account (S6k9GNh0)
No. Windows is definitely the worst platform I've ever developed on. MacOS directory structure is similar to Linux's which I think helps but the fact that it's a controlled and proprietary OS is another. It's probably a little bit more friendly than Linux some times.
Last edited on
First of all, what's the gripe about notepad? Source files are text files--that's it.

Second, why the GCC bashing?! GCC is one of the best compilers available. Also, darkestfright's command line will work...
@Computerquip: Okay. Good point, I has only developed on Mac and GNU/Linux with GTK+. I took a look at the documentation on Windows' API and... @_@

Though I did mean programming programs like smultron. I just can't stand Objective-C for some reason, and it's better to use than than C for the Cocoa APIs.

Also, I wasn't bashing GCC, and I don't think anyone here was. It's an excellent set of compilers, just not always straight forward and some have problems with that.

-Albatross

100th post FTW.
Topic archived. No new replies allowed.