|
-
Nov 17th, 2001, 01:42 PM
#1
Thread Starter
Fanatic Member
Functions - Probably a really dumb question...
Hi,
I'm new to C++, and ive been trying to get a function to work that is in a seperate .cpp file to the main function. I keep getting an error:
Main.obj : error LNK2001: unresolved external symbol "long __cdecl vercin(long,long,char * const,char * const)" (?vercin@@YAJJJQAD0@Z)
how do get it to work? The function is empty at the moment, and so all i have is this:
CPP1.cpp:
PHP Code:
int main()
{
\\...
long vercin (long , long , char [] , char []);
long a = 1;
long b = 2;
long c = 0;
char c [] = "A";
char d [] = "B";
\\...
c = vercin ( a , b , c , d );
\\...
}
CPP2.cpp:
PHP Code:
long vercin (long minval, long maxval , char firstmessage, char secondmessage)
{
return 0;
}
Sorry if this is a really dumb question, but i cant seem to find anything on it Do you have to make it a public or something like in VB? or does it not work like that
Thanx for any help
-
Nov 17th, 2001, 01:47 PM
#2
long vercin (long , long , char [] , char []);
I think if you omit this line, and #include cpp2.cpp it will work
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Nov 17th, 2001, 01:53 PM
#3
Your code shouldnt compile...
Code:
long c = 0;
char c [] = "A";
As for your function, try chaging the last two parameter's data types to char [].
At the moment, it wants a "char", but you are giving it "char []", so it looks for a function with that type of parameter. You havent defined one, but your prototype at the top tells the compiler that it IS there, so it doesnt ask questions during compile time.
But when it gets to the linking stage, it looks for a function defined with those parameters, but there isnt one, so it yells at you.
Z.
-
Nov 17th, 2001, 01:57 PM
#4
Thread Starter
Fanatic Member
Thanx
Thanx, that error has gone now, and 7 different 1s have appeared. I think i know how 2 sort them out
Last edited by Illspirit; Nov 17th, 2001 at 02:04 PM.
-
Nov 17th, 2001, 02:01 PM
#5
Thread Starter
Fanatic Member
oops, messed up with the code there when i filtered the rest of it out! the variables have different names, i just changed them on here for some reason
-
Nov 17th, 2001, 02:18 PM
#6
Thread Starter
Fanatic Member
Nope!...

Compiling...
CPP1.cpp
Linking...
CPP1.obj : error LNK2005: "long __cdecl vercin(long,long,char * const,char * const)" (?vercin@@YAJJJQAD0@Z) already defined in CPP2.obj
CPP3.obj : error LNK2005: "void __cdecl StrAppend(char * const,char * const,long,char *)" (?StrAppend@@YAXQAD0JPAD@Z) already defined in CPP1.obj
Release/Calc 4.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
What does that mean??
-
Nov 17th, 2001, 02:39 PM
#7
The first line you have after
int main()
{
Should be BEFORE the function start. It is called a function prototype and should be on file level. And are you sure CPP2.cpp is compiled together with your main module? The prolem is that the linker (that makes ONE exe out of MANY compiled cpp files) can't find the function (that was the first error). Now the problem seems to come from the #include "CPP2.cpp". That was wrong advice: you NEVER #include cpp files! The linker now finds TWO functinos named vercin and is confused.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 17th, 2001, 05:11 PM
#8
Thread Starter
Fanatic Member
Thanx!
Its compiling!! Thanx CornedBee!!
-
Nov 17th, 2001, 05:54 PM
#9
I remember the confusion created by having a .cpp included in a project, as well as being included in a header file as an implementation!
Z.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|