Results 1 to 9 of 9

Thread: Functions - Probably a really dumb question...

  1. #1

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Unhappy 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";

    \\...

    vercin  );


    \\...




    CPP2.cpp:
    PHP Code:
    long vercin (long minvallong maxval char firstmessagechar 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
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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

  3. #3
    Zaei
    Guest
    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.

  4. #4

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Thumbs up 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.
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  5. #5

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    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
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  6. #6

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    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??
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  8. #8

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Thumbs up Thanx!

    Its compiling!! Thanx CornedBee!!
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  9. #9
    Zaei
    Guest
    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
  •  



Click Here to Expand Forum to Full Width