Arghhhh! LNK 2005 error.
I am at wits end. I was just trying to rejigger the placement of functions in headers and source files so that it would seem more organized, and the code compiled fine before that, but now it keeps throwing me a bunch of LNK 2005 errors and I can't revert to the state it was in before.
So it gives me a total of 62 errors. All of them from a group of functions I placed in the namespace "pis" under the header "phone_initialize.h". It worked fine before and I have no idea why it's giving me grief now.
ot_ok error LNK2005: "int __cdecl pis::set_open_back_unrounded(class phone &)" (?set_open_back_unrounded@pis@@YAHAAVphone@@@Z) already defined in main.obj
ot_ok error LNK2005: "int __cdecl pis::set_close_mid_front_unrounded(class phone &)" (?set_close_mid_front_unrounded@pis@@YAHAAVphone@@@Z) already defined in main.obj
and on and on
I can't isolate the problem so unfortunately, I'm going to have to attach the entire project. The attachment file is a .zip archive so you'll have to change the extension to .zip.
Any help at all would be truly appreciated (not that I didn't appreciate it before, but this is on a different scale).
I didn't look at your zip, but those errors are usually either because you accidentally copied the definition of those functions into multiple places, or because you implemented the functions inside of a header file.
Where do you define (not declare) the set_open_back_unrounded(class phone &) function?
Ohmegosh, it worked. Thank you, thank you, thank you.
But I don't get it.
Originally my functions were placed in a namespace of header called "phone_initialize.h".
They compiled before, but I fooled around with the placement of some stuff that used these functions and then it gives me external link errors. What I actually did was, I abstracted some bit of code that I had in main and placed it in some other source file.
and on and on
So I took your advice and completely removed the functions under the namespace pis and moved it into the source file "phone_initialize.cpp".
It compiled but now I'm worried. I mean, there are no function declarations in the original header but the compiler is still finding the function definition and compiling it. Shouldn't I have at least left the declarations in the header?
Oh, well, I'll save that for a later head-racking.
Again, thank you, merci, danke schoen, gracias, takk, arigato, gamsahabnida, and a thousand other thanks.
The namespace has nothing to do with it. You placed the definitions inside a header file, which is wrong. The solution is to put the definitions inside a namespace in the cpp file:
You can put things into a namespace from as many different files as you want.