error LNK2019: unresolved external symbol
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: error LNK2019: unresolved external symbol

  1. #1
    Join Date
    Dec 2009
    Posts
    6

    error LNK2019: unresolved external symbol

    Hi Friends,

    I am new to C++,I am creating a dll to use in JAVA.
    when i am creating a dll file at compilation i am getting the following error....
    Any one please help me in this regard..........


    Creating library sparsha_Reader.lib and object sparsha_Reader.exp
    sparsha_Reader.obj : error LNK2019: unresolved external symbol "__declspec(dllim
    port) void __cdecl ConnectDevice(char *,char *)" (__imp_?ConnectDevice@@YAXPAD0@
    Z) referenced in function _Java_sparsha_CardReader_CardReadering@8
    sparsha_Reader.obj : error LNK2019: unresolved external symbol "__declspec(dllim
    port) void __cdecl DisconnectDevice(char *)" (__imp_?DisconnectDevice@@YAXPAD@Z)
    referenced in function _Java_sparsha_CardReader_stopCardReader@8
    sparsha_Reader.dll : fatal error LNK1120: 2 unresolved externals


    thanks
    sudheer

  2. #2
    Join Date
    Jul 2002
    Posts
    2,505

    Re: error LNK2019: unresolved external symbol

    Linker cannot find ConnectDevice and DisconnectDevice functions implementation. There are only function prototypes. For example:

    Code:
    void ConnectDevice(char*, char*);
    void DisconnectDevice(char*, char*);
    
    int main()
    {
        ConnectDevice("1", "2");
        DisconnectDevice("1", "2");
    }
    Such program compiles, but linker gives unresolved external symbol error.

  3. #3
    Join Date
    Dec 2009
    Posts
    6

    Re: error LNK2019: unresolved external symbol

    Thanks
    in my header file i declared as
    typedef public char *LPCSTR; // 1byte
    typedef char *DWORD; //4bytes

    DLL_API VOID ConnectDevice( LPCSTR, DWORD);
    DLL_API VOID DisconnectDevice( LPCSTR);

    In my cpp file i useed as

    JNIEXPORT void JNICALL Java_sparsha_CardReader_CardReadering
    (JNIEnv *, jobject){
    char *argv[]={"port=COM1"};
    char *argvs[]={"baudrate=38400"};
    cout<<"Starting cctalk application event manager with caRD\n";
    ConnectDevice( *argv, *argvs);

    }
    JNIEXPORT void JNICALL Java_sparsha_CardReader_stopCardReader
    (JNIEnv *, jobject)
    {
    char *argv[]={"COM1"};
    cout<<"ENDING cctalk application event manager with caRD\n";
    DisconnectDevice( *argv);
    }


    is this correct?
    it is not working....

  4. #4
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,019

    Re: error LNK2019: unresolved external symbol

    Take a look in MSDN at Linker Tools Error LNK2019.

    [ Merged threads ]
    Last edited by ovidiucucu; December 31st, 2009 at 05:47 AM.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  5. #5
    Join Date
    Jul 2002
    Posts
    2,505

    Re: error LNK2019: unresolved external symbol

    Function exported from Dll, should be defined as __declspec(dllexport). In the client project it should be defined as __declspec(dllimport). This is usually done by defining some precompiler constant in the Dll project, and conditional definition, which is expanded as __declspec(dllexport) in the Dll project, and __declspec(dllimport) in the client project.
    To see how it is done, create new Win32 Dll using Visual Studio Application Wizard, and check "Exports symbols" on one of Wizard steps. Created project shows how to export functions and classes from Dll properly.

  6. #6
    Join Date
    Dec 2009
    Posts
    6

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by Alex F View Post
    Linker cannot find ConnectDevice and DisconnectDevice functions implementation. There are only function prototypes. For example:

    Code:
    void ConnectDevice(char*, char*);
    void DisconnectDevice(char*, char*);
    
    int main()
    {
        ConnectDevice("1", "2");
        DisconnectDevice("1", "2");
    }
    Such program compiles, but linker gives unresolved external symbol error.
    Hi
    I am having ICM330_0170DLL.h,ICM330_0170DLL.dll and ICM330_0170DLL.lib files given by my customer now to get a new dll based on these files.I worte a new cpp file as .....
    #define NOMINMAX

    #ifdef WIN32
    #include <windows.h>
    #include <crtdbg.h>
    #endif



    #include <time.h>
    #include <iostream>
    #include <limits>
    #include <vector>
    #include <math.h>
    #include <cstdio>

    #include <jni.h>

    #include "sparsha_CardReader.h"


    #include "ICM330_0170DLL.h"

    using namespace std;


    #undef RANDOMLY_REJECT_BILLS
    #undef ASK_ABOUT_BILLS
    #undef IGNORE_ESCROW_EVENTS

    // Global variables:

    static char *upload_filename = NULL;
    static int amount=0;
    static string str="good";
    jclass cls;
    jfieldID fid;
    jint flag;
    JNIEnv *env;
    jobject obj;
    jstring objst;

    JNIEXPORT void JNICALL Java_sparsha_CardReader_CardReadering
    (JNIEnv *, jobject){
    char *argv[]={"port=COM1"};
    char *argvs[]={"baudrate=38400"};
    cout<<"Starting cctalk application event manager with caRD\n";
    ConnectDevice( *argv, *argvs);

    }
    JNIEXPORT void JNICALL Java_sparsha_CardReader_stopCardReader
    (JNIEnv *, jobject)
    {
    char *argv[]={"COM1"};
    cout<<"ENDING cctalk application event manager with caRD\n";
    DisconnectDevice( *argv);
    }

    and compiling this cpp file by using command:
    Cl/LD sparsha_Reader.cpp /NXCOMPAT /MACHINE:X86 /LINK "D:\sparsha\new\RamyamICM3301\ICM330-0170DLL\ICM330_0170DLL.lib"

    then i am getting this error as described above.
    if i compile using command like....
    Cl/LD sparsha_Reader.cpp /NXCOMPAT /MACHINE:X86 /LINK "D:\sparsha\new\RamyamICM3301\ICM330-0170DLL\ICM330_0170DLL.dll"
    i am getting error ...
    D:\sparsha\new\RamyamICM3301\ICM330-0170DLL\ICM330_0170DLL.dll
    D:\sparsha\new\RamyamICM3301\ICM330-0170DLL\ICM330_0170DLL.dll : fatal error LNK
    1107: invalid or corrupt file: cannot read at 0x2A8



    when i am compiling i am getting .obj,.exp,.lib and .dll.manifest files
    i am new to cpp so what to do now?
    anybody can help me...

  7. #7
    Join Date
    Jul 2002
    Posts
    2,505

    Re: error LNK2019: unresolved external symbol

    Show ConnectDevice and DisonnectDevice definitions from ICM330_0170DLL.h.
    Do you have some code samples using this library? Usually library writers provide such samples.

  8. #8
    Join Date
    Dec 2009
    Posts
    6

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by Alex F View Post
    Show ConnectDevice and DisonnectDevice definitions from ICM330_0170DLL.h.
    Do you have some code samples using this library? Usually library writers provide such samples.

    Hi
    The total header file what they provided me is................................

    #ifndef _ICM330_0170DLL_H_
    #define _ICM330_0170DLL_H_


    #ifdef WIN32
    #include <windows.h>
    #include <crtdbg.h>
    #endif

    #define MAX_DATA_ARRAY_SIZE (1024)


    #pragma pack(8)

    typedef unsigned char BYTE; // 1byte
    typedef unsigned short WORD; // 2bytes
    typedef unsigned long DWORD; //4bytes

    typedef struct
    {
    struct
    {

    CHAR szFilename[ _MAX_FNAME];
    CHAR szRevision[ 32];
    }
    upperDll;

    struct
    {
    CHAR szFilename[ _MAX_FNAME];
    CHAR szRevision[ 32];
    }
    lowerDll;
    }
    DLL_INFORMATION, *LPDLL_INFORMATION;



    /* Data structure for command message */
    typedef struct
    {
    BYTE bCommandCode;
    BYTE bParameterCode;

    struct
    {
    DWORD dwSize;
    LPBYTE lpbBody;
    }
    Data;
    }
    COMMAND, *LPCOMMAND;



    /* Received message type */
    typedef enum
    {
    PositiveReply,
    NegativeReply,
    ReplyReceivingFailure,
    CommandCancellation,
    ReplyTimeout,
    }
    REPLY_TYPE, *LPREPLY_TYPE;



    /* Data structure for positive reply message */
    typedef struct
    {
    BYTE bCommandCode;
    BYTE bParameterCode;

    struct
    {
    BYTE bSt1;
    BYTE bSt0;
    }
    StatusCode;

    struct
    {
    DWORD dwSize;
    BYTE bBody[ MAX_DATA_ARRAY_SIZE];
    }
    Data;
    }
    POSITIVE_REPLY, *LPPOSITIVE_REPLY;



    /* Data structure for negative reply message */
    typedef struct
    {
    BYTE bCommandCode;
    BYTE bParameterCode;

    struct
    {
    BYTE bE1;
    BYTE bE0;
    }
    ErrorCode;

    struct
    {
    DWORD dwSize;
    BYTE bBody[ MAX_DATA_ARRAY_SIZE];
    }
    Data;
    }
    NEGATIVE_REPLY, *LPNEGATIVE_REPLY;



    /* Data structure for reply message */
    typedef struct
    {
    REPLY_TYPE replyType;

    union
    {
    POSITIVE_REPLY positiveReply;
    NEGATIVE_REPLY negativeReply;
    }
    message;

    }
    REPLY, *LPREPLY;



    /*
    --------------------------------------------------------------------------------------------------
    Return codes of the APIs
    */

    #define _ERROR_CODE_ORIGIN (0x0000)


    /*
    Return codes of the following API(s):
    - GetDllInformation
    - ConnectDevice
    - DisconnectDevice
    - ExecuteCommand
    - CancelCommand
    */
    #define _NO_ERROR ( _ERROR_CODE_ORIGIN + 0x0 )
    #define _DEVICE_NOT_CONNECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x1 )
    #define _CANCEL_COMMAND_SESSION_ERROR ( _ERROR_CODE_ORIGIN + 0x2 )
    #define _FAILED_TO_SEND_COMMAND_ERROR ( _ERROR_CODE_ORIGIN + 0x3 )
    #define _FAILED_TO_RECEIVE_REPLY_ERROR ( _ERROR_CODE_ORIGIN + 0x4 )
    #define _COMMAND_CANCELED ( _ERROR_CODE_ORIGIN + 0x5 )
    #define _REPLY_TIMEOUT ( _ERROR_CODE_ORIGIN + 0x6 )



    /*
    Return codes of the following API(s):
    - GetDllInformation

    nothing unique ErrorCode
    */

    /*
    Return codes of the following API(s):
    - ConnectDevice
    */
    #define _CANNOT_CREATE_OBJECT_ERROR ( _ERROR_CODE_ORIGIN + 0x0101 )
    #define _DEVICE_NOT_READY_ERROR ( _ERROR_CODE_ORIGIN + 0x0102 )
    #define _CANNOT_OPEN_PORT_ERROR ( _ERROR_CODE_ORIGIN + 0x0103 )
    #define _FAILED_TO_BEGIN_THREAD_ERROR ( _ERROR_CODE_ORIGIN + 0x0104 )
    #define _DEVICE_ALREADY_CONNECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x0105 )


    /*
    Return codes of the following API(s):
    - DisconnectDevice

    nothing unique ErrorCode
    */

    /*
    Return codes of the following API(s):
    - CancelCommand

    nothing unique ErrorCode
    */

    /*
    Return codes of the following API(s):
    - UpdateFirmware
    */
    #define _UPDATE_FIRMWARE_UNEXPECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x1001 )
    #define _UPDATE_FIRMWARE_UNKNOWN_FILE_TYPE_ERROR ( _ERROR_CODE_ORIGIN + 0x1002 )
    #define _UPDATE_FIRMWARE_CANNOT_OPEN_FILE_ERROR ( _ERROR_CODE_ORIGIN + 0x1003 )
    #define _UPDATE_FIRMWARE_FAILED_TO_ALLOCATE_MEMORY_REGION_ERROR ( _ERROR_CODE_ORIGIN + 0x1004 )
    #define _UPDATE_FIRMWARE_CANNOT_READ_FILE_ERROR ( _ERROR_CODE_ORIGIN + 0x1005 )
    #define _UPDATE_FIRMWARE_CONNECT_DEVICE_FAILED_ERROR ( _ERROR_CODE_ORIGIN + 0x1006 )
    #define _UPDATE_FIRMWARE_DEVICE_ALREADY_CONNECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x1007 )
    #define _UPDATE_FIRMWARE_COMMAND_EXECUTION_FAILED_ERROR ( _ERROR_CODE_ORIGIN + 0x1008 )
    #define _UPDATE_FIRMWARE_NEGATIVE_REPLY_RECEIVED_ERROR ( _ERROR_CODE_ORIGIN + 0x1009 )
    #define _UPDATE_FIRMWARE_DISCONNECT_DEVICE_FAILED_ERROR ( _ERROR_CODE_ORIGIN + 0x100A )
    #define _UPDATE_FIRMWARE_UNEXPECTED_FILE_CONTENTS_ERROR ( _ERROR_CODE_ORIGIN + 0x100B )
    #define _UPDATE_FIRMWARE_IDENTICAL_REVISION_ERROR ( _ERROR_CODE_ORIGIN + 0x100C )


    /*
    Return codes of the following API(s):
    - ICCardTransmit
    */
    #define _ICC_TRANSMIT_UNEXPECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x2001 )
    #define _ICC_TRANSMIT_FAILED_TO_ALLOCATE_MEMORY_REGION_ERROR ( _ERROR_CODE_ORIGIN + 0x2002 )
    #define _ICC_TRANSMIT_ABORT_REQUEST_RECEIVED_ERROR ( _ERROR_CODE_ORIGIN + 0x2003 )
    #define _ICC_TRANSMIT_COMMAND_EXECUTION_FAILED_ERROR ( _ERROR_CODE_ORIGIN + 0x2004 )
    #define _ICC_TRANSMIT_NEGATIVE_REPLY_RECEIVED_ERROR ( _ERROR_CODE_ORIGIN + 0x2005 )


    /*
    Return codes of the following API(s):
    - SAMTransmit
    */
    #define _SAM_TRANSMIT_UNEXPECTED_ERROR ( _ERROR_CODE_ORIGIN + 0x3001 )
    #define _SAM_TRANSMIT_FAILED_TO_ALLOCATE_MEMORY_REGION_ERROR ( _ERROR_CODE_ORIGIN + 0x3002 )
    #define _SAM_TRANSMIT_ABORT_REQUEST_RECEIVED_ERROR ( _ERROR_CODE_ORIGIN + 0x3003 )
    #define _SAM_TRANSMIT_COMMAND_EXECUTION_FAILED_ERROR ( _ERROR_CODE_ORIGIN + 0x3004 )
    #define _SAM_TRANSMIT_NEGATIVE_REPLY_RECEIVED_ERROR ( _ERROR_CODE_ORIGIN + 0x3005 )



    /*
    The end of the declaration of return codes for the APIs
    --------------------------------------------------------------------------------------------------
    */

    typedef VOID ( WINAPI *CALL_BACK_FUNCTION) ( WPARAM, LPARAM);


    #ifndef _DLL_DEVELOPMENT_
    #define DLL_API __declspec( dllimport)
    #else
    #define DLL_API __declspec( dllexport)
    #endif

    DLL_API DWORD WINAPI GetDllInformation( LPDLL_INFORMATION);
    DLL_API DWORD WINAPI ConnectDevice( LPCSTR, CONST DWORD);
    DLL_API DWORD WINAPI DisconnectDevice( LPCSTR);
    DLL_API DWORD WINAPI CancelCommand( LPCSTR);
    DLL_API DWORD WINAPI ExecuteCommand( LPCSTR, CONST COMMAND, CONST DWORD, LPREPLY);
    DLL_API DWORD WINAPI ExecuteCommand2( LPCSTR, LPCOMMAND, CONST DWORD, LPREPLY);
    DLL_API DWORD WINAPI UpdateFirmware( LPCSTR, CONST DWORD, LPCSTR, CONST BOOL, CALL_BACK_FUNCTION, LPDWORD);
    DLL_API DWORD WINAPI ICCardTransmit( LPCSTR, CONST DWORD, LPBYTE, CONST DWORD, LPDWORD, LPBYTE, LPDWORD, LPREPLY);
    DLL_API DWORD WINAPI SAMTransmit( LPCSTR, CONST DWORD, LPBYTE, CONST DWORD, LPDWORD, LPBYTE, LPDWORD, LPREPLY);

    #endif /* _ICM330_0170DLL_H_ */





    they given me one exe file with that device is connecting but i dont know how to see code for that exe file.
    if u can help me i will send that exe file also.

  9. #9
    Join Date
    Apr 1999
    Posts
    27,423

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by sudheerdara View Post
    Hi
    The total header file what they provided me is................................
    Please re-edit your post to use code tags. The code you posted is practically unreadable.

    Regards,

    Paul McKenzie

  10. #10
    Join Date
    Dec 2009
    Posts
    6

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by Paul McKenzie View Post
    Please re-edit your post to use code tags. The code you posted is practically unreadable.

    Regards,

    Paul McKenzie
    Hi
    I dont know how to re-edit my post.
    does any one help me to know how to see source code from an exe or dll file
    thanks
    Last edited by sudheerdara; January 4th, 2010 at 11:05 PM. Reason: typing mistake

  11. #11
    Join Date
    Apr 1999
    Posts
    27,423

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by sudheerdara View Post
    Hi
    I dont know how to re-edit my post.
    Go back to your post, click on "Edit", and then add the code tags.

    Regards,

    Paul McKenzie

  12. #12
    Join Date
    Apr 1999
    Posts
    27,423

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by sudheerdara View Post
    Hi Friends,

    I am new to C++,I am creating a dll to use in JAVA.
    You are probably trying to use the JNI technology of JAVA. If so, the Sun website has plenty of beginner examples.

    http://java.sun.com/developer/online...CBook/jni.html

    Why not go to the Sun website, and try those examples first, before trying to do this yourself with your own code? When I was first getting JNI to work, I went through the simple sample programs first before creating the library that I was working on. If the sample at the link doesn't work for you, then at least everyone here will have some kind of concrete reference point as to what is failing.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; January 4th, 2010 at 11:31 PM.

  13. #13
    Join Date
    Jul 2002
    Posts
    2,505

    Re: error LNK2019: unresolved external symbol

    Reading this h-file, I don't see any reason why this program is not linked. The only strange point is your code:

    typedef public char *LPCSTR; // 1byte
    typedef char *DWORD; //4bytes

    Why do you need the second typedef? Possibly it prevents compiler to create correct external dependency, which should be resolved by linker.

  14. #14
    Join Date
    Dec 2009
    Posts
    6

    Re: error LNK2019: unresolved external symbol

    Quote Originally Posted by Alex F View Post
    Reading this h-file, I don't see any reason why this program is not linked. The only strange point is your code:

    typedef public char *LPCSTR; // 1byte
    typedef char *DWORD; //4bytes

    Why do you need the second typedef? Possibly it prevents compiler to create correct external dependency, which should be resolved by linker.

    Hi
    In actual h-file i don't have typedef's....but when i compile cpp file in which i included these header file i m getting errors so i wrote these typedef's .I don't know how to compile without wrirting these typedef's.

  15. #15
    Join Date
    Nov 2011
    Posts
    1

    Re: error LNK2019: unresolved external symbol

    Hello, you sudheerdara locate the libraries. Lib and dll files in C: \ windows \ system32, that if you use visual c + +, plus you do link to. Lib you have

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center