unresolved external symbol/using an external dll

Discussion in 'C++' started by Scott Allen, Apr 30, 2004.

  1. Scott Allen

    Scott Allen Guest

    Hello,

    I'm new to C++ development and I'm trying out figure out the cause of
    an 'unresolved external symbol' error that I'm receiving when
    compiling. Here is some history on what I'm doing:

    I have an existing VC++ project that mostly just reads a SQL Server
    database does some work on the data and insert the results into
    another table. I have the need to incorproate some functionality from
    a certain dll named cedb300.dll. cedb300.dll is an unsupported
    Microsoft dll that allows the reading and writing of Windows CE
    databases to a disk (as opposed to an actual device). I have a list of
    function signatures that are externally available from this dll.

    I only have access to the dll, so I used a program called 'DLL to Lib'
    (http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
    file from the dll. This appeared to be successful. I copied both the
    cedb300.dll and cedb300.lib files into my VC++ project directory and
    added cedb300.lib to 'Projects->Settings->Link->Object/library
    modules'

    I add a call in my VC++ project to one of the functions in
    cedb300.dll, but when I try to compile I get a 'unresolved external
    symbol' error message. Naturally, removing the call to the function
    causes the error to go away and my app compiles.

    So, being new to VC++, I'm not sure if there's some more code I need
    to add to my source to allow me to call functions from an external
    dll, or if VC++ is simply not able to access the .lib files or if the
    lib file is corrupted, or all of the above.

    Is there something else I need to add to my code/project to allow me
    to call functions from an external dll? Or is there another tool
    someone can recommend to create a lib from a dll?

    Thanks very much,
    -Scott
     
    Scott Allen, Apr 30, 2004
    #1
    1. Advertising

  2. I suspect that you have a calling convention problem. The linker of course
    tells you the complete name of the undefined symbol, what you need to do is
    dumpbin /exports on the DLL (or dumpbin /symbols on the lib) and find the
    name in the library that you think should match the undefined external.
    Once you have those names, post back with both names and someone can figure
    out what's wrong (it's probably something like lack of __stdcall on your
    function prototypes).

    -cd

    Scott Allen wrote:
    > Hello,
    >
    > I'm new to C++ development and I'm trying out figure out the cause of
    > an 'unresolved external symbol' error that I'm receiving when
    > compiling. Here is some history on what I'm doing:
    >
    > I have an existing VC++ project that mostly just reads a SQL Server
    > database does some work on the data and insert the results into
    > another table. I have the need to incorproate some functionality from
    > a certain dll named cedb300.dll. cedb300.dll is an unsupported
    > Microsoft dll that allows the reading and writing of Windows CE
    > databases to a disk (as opposed to an actual device). I have a list of
    > function signatures that are externally available from this dll.
    >
    > I only have access to the dll, so I used a program called 'DLL to Lib'
    > (http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
    > file from the dll. This appeared to be successful. I copied both the
    > cedb300.dll and cedb300.lib files into my VC++ project directory and
    > added cedb300.lib to 'Projects->Settings->Link->Object/library
    > modules'
    >
    > I add a call in my VC++ project to one of the functions in
    > cedb300.dll, but when I try to compile I get a 'unresolved external
    > symbol' error message. Naturally, removing the call to the function
    > causes the error to go away and my app compiles.
    >
    > So, being new to VC++, I'm not sure if there's some more code I need
    > to add to my source to allow me to call functions from an external
    > dll, or if VC++ is simply not able to access the .lib files or if the
    > lib file is corrupted, or all of the above.
    >
    > Is there something else I need to add to my code/project to allow me
    > to call functions from an external dll? Or is there another tool
    > someone can recommend to create a lib from a dll?
    >
    > Thanks very much,
    > -Scott
     
    Carl Daniel [VC++ MVP], Apr 30, 2004
    #2
    1. Advertising

  3. Scott Allen

    Karthik Guest

    Scott Allen wrote:

    > Hello,
    >
    > I'm new to C++ development and I'm trying out figure out the cause of
    > an 'unresolved external symbol' error that I'm receiving when
    > compiling. Here is some history on what I'm doing:
    >
    > I have an existing VC++ project that mostly just reads a SQL Server
    > database does some work on the data and insert the results into
    > another table. I have the need to incorproate some functionality from
    > a certain dll named cedb300.dll. cedb300.dll is an unsupported
    > Microsoft dll that allows the reading and writing of Windows CE
    > databases to a disk (as opposed to an actual device). I have a list of
    > function signatures that are externally available from this dll.
    >
    > I only have access to the dll, so I used a program called 'DLL to Lib'
    > (http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
    > file from the dll. This appeared to be successful. I copied both the
    > cedb300.dll and cedb300.lib files into my VC++ project directory and
    > added cedb300.lib to 'Projects->Settings->Link->Object/library
    > modules'
    >
    > I add a call in my VC++ project to one of the functions in
    > cedb300.dll, but when I try to compile I get a 'unresolved external
    > symbol' error message. Naturally, removing the call to the function
    > causes the error to go away and my app compiles.
    >
    > So, being new to VC++, I'm not sure if there's some more code I need
    > to add to my source to allow me to call functions from an external
    > dll, or if VC++ is simply not able to access the .lib files or if the
    > lib file is corrupted, or all of the above.
    >

    Check out project options to the lib file that you are using.
    Also make sure that you pass the relevant /libpath switch option with
    the directory so that the linker can locate the lib file for linking.

    HTH

    --
    Karthik
    Humans please 'removeme_' for my real email.
     
    Karthik, Apr 30, 2004
    #3
  4. Actually Windows CE only has cdecl calling convention.

    Use dumpbin /exports on the library file. And then dumpbin /relocations on
    the .obj file that calls the function.

    Most likely you need to have the functions declared with extern "C". You
    probably have a problem with name mangling. If so, you would see mangled
    names when you dumpbin the .obj file.

    --

    Michael Salamone [eMVP]
    Entrek Software, Inc.
    www.entrek.com



    "Carl Daniel [VC++ MVP]" <>
    wrote in message news:...
    > I suspect that you have a calling convention problem. The linker of

    course
    > tells you the complete name of the undefined symbol, what you need to do

    is
    > dumpbin /exports on the DLL (or dumpbin /symbols on the lib) and find the
    > name in the library that you think should match the undefined external.
    > Once you have those names, post back with both names and someone can

    figure
    > out what's wrong (it's probably something like lack of __stdcall on your
    > function prototypes).
    >
    > -cd
    >
    > Scott Allen wrote:
    > > Hello,
    > >
    > > I'm new to C++ development and I'm trying out figure out the cause of
    > > an 'unresolved external symbol' error that I'm receiving when
    > > compiling. Here is some history on what I'm doing:
    > >
    > > I have an existing VC++ project that mostly just reads a SQL Server
    > > database does some work on the data and insert the results into
    > > another table. I have the need to incorproate some functionality from
    > > a certain dll named cedb300.dll. cedb300.dll is an unsupported
    > > Microsoft dll that allows the reading and writing of Windows CE
    > > databases to a disk (as opposed to an actual device). I have a list of
    > > function signatures that are externally available from this dll.
    > >
    > > I only have access to the dll, so I used a program called 'DLL to Lib'
    > > (http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
    > > file from the dll. This appeared to be successful. I copied both the
    > > cedb300.dll and cedb300.lib files into my VC++ project directory and
    > > added cedb300.lib to 'Projects->Settings->Link->Object/library
    > > modules'
    > >
    > > I add a call in my VC++ project to one of the functions in
    > > cedb300.dll, but when I try to compile I get a 'unresolved external
    > > symbol' error message. Naturally, removing the call to the function
    > > causes the error to go away and my app compiles.
    > >
    > > So, being new to VC++, I'm not sure if there's some more code I need
    > > to add to my source to allow me to call functions from an external
    > > dll, or if VC++ is simply not able to access the .lib files or if the
    > > lib file is corrupted, or all of the above.
    > >
    > > Is there something else I need to add to my code/project to allow me
    > > to call functions from an external dll? Or is there another tool
    > > someone can recommend to create a lib from a dll?
    > >
    > > Thanks very much,
    > > -Scott

    >
    >
     
    Michael J. Salamone [eMVP], May 1, 2004
    #4
  5. Michael J. Salamone [eMVP] wrote:
    > Actually Windows CE only has cdecl calling convention.


    I got the impression that the OP is using code to read a CE database outside
    WinCE. The presence or absense of extern "C" may very well be the problem
    as well - good point.

    -cd
     
    Carl Daniel [VC++ MVP], May 1, 2004
    #5
  6. Scott Allen

    Scott Allen Guest

    Thanks for your responses. I found a link on the web that suggested
    adding 'extern "C"' to the beginning of the function definitions in my
    header file (a windows ce header named WINDBASE.H). This seemed to
    solve my problem. I'm now able to compile and access the functions in
    the lib file from within my application. Some functions throw a
    runtime error, but I think that can be fixed.

    The thing I'm confused about is that it seems that I should be able to
    use just 'extern' instead of 'extern "C"'... the fact that the
    function come from a C/C++ library should be the default, right?

    Thanks, -Scott

    Karthik <> wrote in message news:<4092b10c$1@darkstar>...
    > Scott Allen wrote:
    >
    > > Hello,
    > >
    > > I'm new to C++ development and I'm trying out figure out the cause of
    > > an 'unresolved external symbol' error that I'm receiving when
    > > compiling. Here is some history on what I'm doing:
    > >
    > > I have an existing VC++ project that mostly just reads a SQL Server
    > > database does some work on the data and insert the results into
    > > another table. I have the need to incorproate some functionality from
    > > a certain dll named cedb300.dll. cedb300.dll is an unsupported
    > > Microsoft dll that allows the reading and writing of Windows CE
    > > databases to a disk (as opposed to an actual device). I have a list of
    > > function signatures that are externally available from this dll.
    > >
    > > I only have access to the dll, so I used a program called 'DLL to Lib'
    > > (http://www.binary-soft.com/dll2lib/dll2lib.htm) to generate a .lib
    > > file from the dll. This appeared to be successful. I copied both the
    > > cedb300.dll and cedb300.lib files into my VC++ project directory and
    > > added cedb300.lib to 'Projects->Settings->Link->Object/library
    > > modules'
    > >
    > > I add a call in my VC++ project to one of the functions in
    > > cedb300.dll, but when I try to compile I get a 'unresolved external
    > > symbol' error message. Naturally, removing the call to the function
    > > causes the error to go away and my app compiles.
    > >
    > > So, being new to VC++, I'm not sure if there's some more code I need
    > > to add to my source to allow me to call functions from an external
    > > dll, or if VC++ is simply not able to access the .lib files or if the
    > > lib file is corrupted, or all of the above.
    > >

    > Check out project options to the lib file that you are using.
    > Also make sure that you pass the relevant /libpath switch option with
    > the directory so that the linker can locate the lib file for linking.
    >
    > HTH
     
    Scott Allen, May 1, 2004
    #6
  7. You're right - I didn't read closely enough.

    So, it's one of the two - the calling convention or the name mangling.
    Dumpbin will shed light.

    If you see _ and something like @8 at the end of a name, it's stdcall,
    otherwise cdecl. If it's name mangling, you'll know it when you see it -
    lot's of extra characters in front and in back of the name. And, it just
    might be both. You'll have to adjust the declarations in your header file
    appropriately.

    --

    Michael Salamone [eMVP]
    Entrek Software, Inc.
    www.entrek.com



    "Carl Daniel [VC++ MVP]" <>
    wrote in message news:%...
    > Michael J. Salamone [eMVP] wrote:
    > > Actually Windows CE only has cdecl calling convention.

    >
    > I got the impression that the OP is using code to read a CE database

    outside
    > WinCE. The presence or absense of extern "C" may very well be the problem
    > as well - good point.
    >
    > -cd
    >
    >
    >
     
    Michael J. Salamone [eMVP], May 1, 2004
    #7
  8. "Scott Allen" <> wrote in message
    news:...
    > Thanks for your responses. I found a link on the web that suggested
    > adding 'extern "C"' to the beginning of the function definitions in my
    > header file (a windows ce header named WINDBASE.H). This seemed to
    > solve my problem. I'm now able to compile and access the functions in
    > the lib file from within my application. Some functions throw a
    > runtime error, but I think that can be fixed.
    >
    > The thing I'm confused about is that it seems that I should be able to
    > use just 'extern' instead of 'extern "C"'... the fact that the
    > function come from a C/C++ library should be the default, right?
    >
    > Thanks, -Scott
    >


    There is no language called C/C++, AFAIK its an invention of job recruitment
    agencies. In reality C and C++ are two different languages and C++ typically
    needs to be told that an external function has been compiled as C.

    john
     
    John Harrison, May 1, 2004
    #8
  9. Scott Allen

    Scott Allen Guest

    Thanks everyone!

    "John Harrison" <> wrote in message news:<c70hjh$gmq4v$-berlin.de>...
    > "Scott Allen" <> wrote in message
    > news:...
    > > Thanks for your responses. I found a link on the web that suggested
    > > adding 'extern "C"' to the beginning of the function definitions in my
    > > header file (a windows ce header named WINDBASE.H). This seemed to
    > > solve my problem. I'm now able to compile and access the functions in
    > > the lib file from within my application. Some functions throw a
    > > runtime error, but I think that can be fixed.
    > >
    > > The thing I'm confused about is that it seems that I should be able to
    > > use just 'extern' instead of 'extern "C"'... the fact that the
    > > function come from a C/C++ library should be the default, right?
    > >
    > > Thanks, -Scott
    > >

    >
    > There is no language called C/C++, AFAIK its an invention of job recruitment
    > agencies. In reality C and C++ are two different languages and C++ typically
    > needs to be told that an external function has been compiled as C.
    >
    > john
     
    Scott Allen, May 2, 2004
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Harrison
    Replies:
    0
    Views:
    1,053
    John Harrison
    Jul 20, 2003
  2. Izak Pretorius
    Replies:
    2
    Views:
    1,581
    Christopher
    Sep 14, 2003
  3. Rodolphe
    Replies:
    4
    Views:
    1,081
    Rodolphe
    Oct 3, 2003
  4. Mastadex
    Replies:
    4
    Views:
    733
    Mastadex
    Oct 1, 2005
  5. Replies:
    3
    Views:
    252
Loading...

Share This Page