Author | Message | Time |
---|---|---|
R.a.B.B.i.T | [code]functions.obj : error LNK2005: "void __stdcall timestamp(void)" (?timestamp@@YGXXZ) already defined in main.obj functions.obj : error LNK2005: "char * __stdcall readini(char *,char *,char *)" (?readini@@YGPADPAD00@Z) already defined in main.obj functions.obj : error LNK2005: "bool __stdcall writeini(char *,char *,char *)" (?writeini@@YG_NPAD00@Z) already defined in main.obj functions.obj : error LNK2005: "char * __stdcall apppath(void)" (?apppath@@YGPADXZ) already defined in main.obj[/code] I only get on build, sometimes. If I change the declares to just like "void timestamp()" then it'll work for a while, then I'll have to change it to "void __cdecl timestamp()" and then to "void __stdcall timestamp()" and so forth. It's really starting to piss me off. Anyone know what's going on? [edit] Now they won't go away no matter what I do. | July 5, 2005, 4:32 AM |
K | sounds like you've defined functions in a header file which is included by several different source files. Declare the functions in a header and define them in a seperate source file. Edit: or it could be a problem with some object files not being generated when you only change one. -- in this case trying removing the object files (ie, make clean) and rebuilding. it's hard to say without seeing your code. | July 5, 2005, 5:14 AM |
R.a.B.B.i.T | [code] //functions.h #ifndef FUNCTIONS_H #define FUNCTIONS_H #pragma once void timestamp(); char* readini(char *file, char *section, char *key); bool writeini(char *section, char *key, char *value); char* apppath(); #include "functions.cpp" #endif[/code] [code]//functions.cpp #include <stdio.h> #include <windows.h> void timestamp() { SYSTEMTIME st; GetLocalTime(&st); printf("[%02i:%02i:%02i] ", st.wHour, st.wMinute, st.wSecond); } char* readini(char *file, char *section, char *key) { char *outbuf = new char[255]; memset(outbuf, 0x00, 255); GetPrivateProfileString(section, key, "", outbuf, sizeof(outbuf), file); return outbuf; } bool writeini(char *section, char *key, char *value) { return true; } char* apppath() { char buff[1024]; GetModuleFileName(NULL, buff, sizeof(buff)); char p[1024]; char *result; strcpy(p, (const char *) buff); strrev(p); result = strchr(p, '\\'); strrev(result); strcpy((char *)buff, (const char*)result); return buff; }[/code] [code]//main.cpp #include <stdio.h> #include "functions.h" int main() { timestamp(); char *path = apppath(); printf("%s\n", path); return 0; }[/code] [edit] Hrm :\ | July 5, 2005, 11:30 PM |
shout | [code] #include "functions.cpp" [/code] There's your problem. Erase that. Then put this in the cpp file: [code] #include "functions.h" [/code] And never call anything "functions". | July 6, 2005, 12:22 AM |
K | [quote author=Shout link=topic=12075.msg119127#msg119127 date=1120609322] [code] #include "functions.cpp" [/code] There's your problem. Erase that. [/quote] Yeah. why would you include a source file anyway? The only reason you should ever do that is if you're writing templated functions and don't want to directly put them in the header file. But even then, it's a hack :P | July 6, 2005, 12:38 AM |
R.a.B.B.i.T | [quote author=Shout link=topic=12075.msg119127#msg119127 date=1120609322] [code] #include "functions.cpp" [/code] There's your problem. Erase that. Then put this in the cpp file: [code] #include "functions.h" [/code]Tried it, didn't work (same errors). Also note that I like calling them "functions.h" and "functions.cpp", it tells me what they are: random, non-linked functions. And never call anything "functions". [/quote]I like calling things functions :\ Anyways, I fixed it, but I don't remember how.... | July 6, 2005, 3:34 AM |