• Welcome to Valhalla Legends Archive.
 

Errors...I can't figure out...

Started by R.a.B.B.i.T, July 04, 2005, 11:32 PM

Previous topic - Next topic

R.a.B.B.i.T

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

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.

K

#1
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.

R.a.B.B.i.T

#2

//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


//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;
}


//main.cpp
#include <stdio.h>
#include "functions.h"

int main()
{
timestamp();

char *path = apppath();
printf("%s\n", path);

return 0;
}


[edit]
Hrm :\

shout

#3

#include "functions.cpp"


There's your problem. Erase that.

Then put this in the cpp file:


#include "functions.h"


And never call anything "functions".

K

Quote from: Shout on July 05, 2005, 07:22 PM

#include "functions.cpp"


There's your problem. Erase that.

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

R.a.B.B.i.T

#5
Quote from: Shout on July 05, 2005, 07:22 PM

#include "functions.cpp"


There's your problem. Erase that.

Then put this in the cpp file:


#include "functions.h"
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".
I like calling things functions :\

Anyways, I fixed it, but I don't remember how....