Link error 
Author Message
 Link error

Hi,

I have a rand function that I defined in the rand.cpp file which I have
included in my program.  I don't have any problem with complie, however, it
always comes back with link errors:

ompiling...
simulation1.cpp
RAND.CPP
Linking...

defined in simulation1.obj

already defined in simulation1.obj

already defined in simulation1.obj
Debug/simulation1.exe : fatal error LNK1169: one or more multiply defined
symbols found
Error executing link.exe.

Here is part of my program:

#include <iostream.h>
#include <math.h>
#include "c:\rand.cpp"

int main()
{
 int i = 1;
 double number1;
 number1 = rand(i);
 cout << number1;
 return 0;

Quote:
}

Can someone please explain to me what did I do wrong?  Thank you.


Wed, 09 Feb 2005 01:13:43 GMT  
 Link error


Quote:
> I have a rand function that I defined in the rand.cpp file which I have
> included in my program.  I don't have any problem with complie, however,
> it always comes back with link errors:

Included? This sounds bad already.

Quote:
> ompiling...
> simulation1.cpp
> RAND.CPP
> Linking...

> already defined in simulation1.obj
> RAND.OBJ : error LNK2005: "void __cdecl randst(long,int)"


> already defined in simulation1.obj
> Debug/simulation1.exe : fatal error LNK1169: one or more multiply
> defined symbols found
> Error executing link.exe.

> Here is part of my program:

> #include <iostream.h>

This is not a C include file.

Quote:
> #include <math.h>
> #include "c:\rand.cpp"

No. You don't include source files unless you want people to get mad at
you. You can do this but don't. Compile rand.cpp and then link against the
resulting object file. Create rand.h and put the function prototype of
your horribly named rand() function there. Better yet, get out of the C
library name space and name your function myRand() instead.

Besides, it should be .c not .cpp since the latter is typically used for
C++ source files. Since this is comp.lang.c and not comp.lang.c++ we
should stick with .c files.

Quote:
> int main()
> {
>  int i = 1;
>  double number1;
>  number1 = rand(i);
>  cout << number1;

Syntax error, this is C++ not C.

Quote:
>  return 0;
> }

> Can someone please explain to me what did I do wrong?  Thank you.

I think you need to read, at least once, K&R's "The C Programming
Language, 2nd Ed".


Wed, 09 Feb 2005 01:28:58 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Linking error when link for Codeview

2. VC 4.2 link error linking static libraries from VC 6.0

3. Link Errors in Static Link

4. Link errors during static link

5. LINK : error : Internal error during Pass1

6. LINK : error : Internal error during EmitMap

7. LINK : error : Internal error during SetupPhase

8. Link error: 'Internal error during ReadSymbolTable'

9. LINK : error : Internal error during EmitMap

10. Link Errors : error LNK2005 and LNK2004

11. LINK : error : Internal error during Pass1

12. LINK : error : Internal error during ReadSymbolTable

 

 
Powered by phpBB® Forum Software