Like Tree7Likes
  • 1 Post By Elysia
  • 1 Post By Elysia
  • 1 Post By Elysia
  • 1 Post By Elysia
  • 1 Post By Elysia
  • 1 Post By smokeyangel
  • 1 Post By smokeyangel

Unresolved External In Class In VC++ 2008

This is a discussion on Unresolved External In Class In VC++ 2008 within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a new class for performing some functions. Basically I am writing a ECC math class. ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18

    Unresolved External In Class In VC++ 2008

    I am trying to write a new class for performing some functions.
    Basically I am writing a ECC math class.

    I declared a variable as :

    ECC a;
    a.InitEllipticCurve(a, b, prime); //This is where i get the Unresolved external.

    I've included the ECC.h file..

    Here is the error :

    1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall ECC::InitEllipticCurve(__int64,__int64,__int64)" (?InitEllipticCurve@ECC@@QAEX_J00@Z) referenced in function _main

    I am new to C++ & I cant understand the reason of this error, which I think is a linker error.

    Best Regards
    KKR

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Is EEC for external library? If so, you need to add its .lib file under linker additional input files (see project properties -> linker).
    If it's a source file in your project, then make sure to add all its .cpp files to your project.
    KKR_WE_RULE likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18
    ECC is a class that I am writing from scratch.
    It has only one cpp file, ECC.cpp.

    I've added the ECC.h in my project, do I need to add the ECC.cpp too ?

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Yes, you do. You need to add all your source files to the project.
    Header files are optional, but recommended.
    KKR_WE_RULE likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18
    lol.. Now the list of errors is even greater

    1>------ Build started: Project: ECLibrary, Configuration: Debug Win32 ------
    1>Compiling...
    1>Source.cpp
    1>Linking...
    1>ECC.obj : error LNK2005: "public: __thiscall ECC::ECC(void)" (??0ECC@@QAE@XZ) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 __cdecl ModInverse(__int64,__int64)" (?ModInverse@@YA_J_J0@Z) already defined in Source.obj
    1>ECC.obj : error LNK2005: "void __cdecl InitEllipticCurve(__int64,__int64,__int64)" (?InitEllipticCurve@@YAX_J00@Z) already defined in Source.obj
    1>ECC.obj : error LNK2005: "void __cdecl ECGetPoints(__int64,__int64)" (?ECGetPoints@@YAX_J0@Z) already defined in Source.obj
    1>ECC.obj : error LNK2005: "void __cdecl DoubleECPoints(void)" (?DoubleECPoints@@YAXXZ) already defined in Source.obj
    1>ECC.obj : error LNK2005: "public: __thiscall ECC::~ECC(void)" (??1ECC@@QAE@XZ) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 sumY" (?sumY@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "bool Infinity" (?Infinity@@3_NA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 a" (?a@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 YCoordinate" (?YCoordinate@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 b" (?b@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 doubledY" (?doubledY@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 XCoordinate" (?XCoordinate@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 doubledX" (?doubledX@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 P" (?P@@3_JA) already defined in Source.obj
    1>ECC.obj : error LNK2005: "__int64 sumX" (?sumX@@3_JA) already defined in Source.obj
    1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall ECC::InitEllipticCurve(__int64,__int64,__int64)" (?InitEllipticCurve@ECC@@QAEX_J00@Z) referenced in function _main
    1>C:\Users\Priyabrata\Documents\Visual Studio 2008\Projects\ECLibrary\Debug\ECLibrary.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Users\Priyabrata\Documents\Visual Studio 2008\Projects\ECLibrary\ECLibrary\Debug\BuildLog.h tm"
    1>ECLibrary - 18 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Now what ?

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Would you mind showing your includes for Source.cpp?
    KKR_WE_RULE likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18

  8. #8
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Remove #include "ECC.cpp".
    KKR_WE_RULE likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18
    Then the original problem remains..

    1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall ECC::InitEllipticCurve(__int64,__int64,__int64)" (?InitEllipticCurve@ECC@@QAEX_J00@Z) referenced in function _main

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,620
    Looking over the source, here are your problems:

    void ECC::InitEllipticCurve(__int64 A, __int64 B, __int64 Prime)

    Add part in red.
    Similarly for DoubleECPoints and ECGetPoints.
    Do not include source files.

    Also suggest:
    Get rid of conio.h. It isn't used and it isn't standard.
    Replace __int64 with long long.
    Add declaration for ModInverse.
    Work on getting rid of those globals.

    So why did this error occur? Basically, you told the compiler that there was a member function InitEllipticCurve. But really there wasn't. It was global and not part of the class. So the linker couldn't find it, which means it couldn't create a functional program, hence the error.
    Last edited by Elysia; 07-08-2011 at 05:00 PM.
    KKR_WE_RULE likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    Indeed, including source files is a Bad Thing.

    The compiler needs to know about functions defined in other source files (since the compiler does 1 source file at a time). That's exactly what a header file is for: and your header is fine.

    The linker matches up references to definitions. In this case, you hadn't defined any of the functions declared in your header file, because as Elysia points out, the functions you defined aren't members of the ECC class without the ECC:: prefix.
    KKR_WE_RULE likes this.

  12. #12
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18
    Doesn't help

    Now my ECC.h reads as :

    Code:
    #include <windows.h>
    #pragma once
    class ECC
    {
    public:
    	ECC(void);
        void ECC::InitEllipticCurve(__int64 A, __int64 B, __int64 Prime);
    	void ECC::DoubleECPoints();
    	void ECC::ECGetPoints(__int64 xcoordinate, __int64 ycoordinate);
    	~ECC(void);
    };

    1>------ Build started: Project: ECLibrary, Configuration: Release Win32 ------
    1>Compiling...
    1>Source.cpp
    1>Compiling...
    1>ECC.cpp
    1>Linking...
    1>Source.obj : error LNK2001: unresolved external symbol "public: void __thiscall ECC::InitEllipticCurve(__int64,__int64,__int64)" (?InitEllipticCurve@ECC@@QAEX_J00@Z)
    1>C:\Users\Priyabrata\Documents\Visual Studio 2008\Projects\ECLibrary\Release\ECLibrary.exe : fatal error LNK1120: 1 unresolved externals
    1>Build log was saved at "file://c:\Users\Priyabrata\Documents\Visual Studio 2008\Projects\ECLibrary\ECLibrary\Release\BuildLog .htm"
    1>ECLibrary - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  13. #13
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    Your ECC.h was fine before.

    It is your ECC.cpp that you need to make the modification to
    KKR_WE_RULE likes this.

  14. #14
    Registered User
    Join Date
    Jan 2011
    Location
    Calcutta, India, India
    Posts
    18
    I've got it
    Now it seems to be working
    Thanx a bunch guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unresolved external on vector inside class constructor
    By Mario F. in forum C++ Programming
    Replies: 13
    Last Post: 06-20-2006, 12:44 PM
  2. Unresolved External
    By ElWhapo in forum Windows Programming
    Replies: 1
    Last Post: 05-08-2005, 08:21 PM
  3. unresolved external, template class prob
    By *ClownPimp* in forum C++ Programming
    Replies: 3
    Last Post: 07-19-2003, 12:55 AM
  4. Unresolved external
    By Megatron in forum Windows Programming
    Replies: 2
    Last Post: 01-10-2003, 08:40 PM
  5. Unresolved external...
    By Yoshi in forum C++ Programming
    Replies: 2
    Last Post: 11-13-2002, 10:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21