ewe@gator.cacs.usl.edu (Edwin Wallace Elberson) (03/24/90)
Here's a problem I'm having with c++ (AT&T; I don't remember the version right off hand...) Actually, it's the preprocessor where (I suspect) I'm having the problem. I've never had trouble in good old C, but then again, things are different now... Basically, I'm trying to include the same header file in two .c files, using #ifndef to control multiple definitions. Here are the three files: /* file a.h */ #ifndef TEST #define TEST 1 #include <stream.h> class cl1 { int a; public: void print_a(); }; void cl1::print_a() { cout << a << "\n"; } #endif ---------------------------------------------------------------------- /* file a.c */ #include <stream.h> #include "a.h" main () { extern void test_fn(); cl1 cl; test_fn(); } ---------------------------------------------------------------------- /* file b.c */ #include <stream.h> #include "a.h" void test_fn() { cout << "this is a test...\n"; } I compile with "CC a.c b.c" and everything works fine until the ld portion at the end, where I get "blah blah print_a() multiply defined in b.o" or something to that effect. I know there's something I'm doing wrong here, but I don't know what it is. I looked at the intermediate files a..c and b..c, and sure enough, print_a() is declared and defined in both. It's like the #ifndef isn't working at all. Does anyone know what's going on here? Please?!?