Unresolved Externals errors when using external .lib file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • robintw

    Unresolved Externals errors when using external .lib file

    Hi all,

    I'm trying to use some functions which are in an external library file called qhdlc.lib from within my C++ .Net program. I have a header file for this library (qhdlc.h) and have set the library as an "additional dependency" in Project Properties->Linker->Input. Even though I have done all of that, I still get unresolved token errors for every function in the library.

    Sadly, I do not have access to the source code for the library - but need to access it from my C++ .Net program. The library is written in ANSI C, and works fine when used from a program written in ANSI C and compiled with an ANSI C compiler.

    I have no idea what to check next. I have some books on C++ .Net, but they don't seem to have any help, and I haven't been able to find anthing using Google.

    Anyone got any ideas?

    Robin
    ---
    Posted via DotNetSlackers. com
  • William DePalo [MVP VC++]

    #2
    Re: Unresolved Externals errors when using external .lib file

    <robintwwrote in message news:uizwQfnAHH A.4212@TK2MSFTN GP02.phx.gbl...
    I'm trying to use some functions which are in an external library file
    called qhdlc.lib from within my C++ .Net program. I have a header file for
    this library (qhdlc.h) and have set the library as an "additional
    dependency" in Project Properties->Linker->Input. Even though I have done
    all of that, I still get unresolved token errors for every function in the
    library.
    >
    Sadly, I do not have access to the source code for the library - but need
    to access it from my C++ .Net program. The library is written in ANSI C,
    and works fine when used from a program written in ANSI C and compiled
    with an ANSI C compiler.
    >
    I have no idea what to check next. I have some books on C++ .Net, but they
    don't seem to have any help, and I haven't been able to find anthing using
    Google.
    >
    Anyone got any ideas?
    It could be a problem of C++ name decoration, aka name mangling

    At the top of the header for the library written in C add this (or create a
    new header from the old with the modifications)

    #ifdef __cplusplus
    extern "C" {
    #endif

    and at the bottom add this

    #ifdef __cplusplus
    extern }
    #endif

    And rebuild the entire project.

    Regards,
    Will



    Comment

    • robintw

      #3
      Re: Unresolved Externals errors when using external .l ...

      Hi,

      Thanks for the response. I've tried doing that and the unresolved externals errors have disappeared (hooray!) but there is a new fatal linker error:

      LNK1104: cannot open file "libc.lib"

      Any ideas what I should do? I've searched my whole project, and nowhere does it seem to reference libc.lib (obviously I can't check in the lib file because it is compiled and I do not have access to the source code).

      Robin
      ---
      Posted via DotNetSlackers. com

      Comment

      • William DePalo [MVP VC++]

        #4
        Re: Unresolved Externals errors when using external .l ...

        <robintwwrote in message news:ePYzVFoAHH A.3560@TK2MSFTN GP03.phx.gbl...
        Thanks for the response.
        You are welcome.
        I've tried doing that and the unresolved externals errors
        have disappeared (hooray!) but there is a new fatal linker
        error:
        >
        LNK1104: cannot open file "libc.lib"
        I see.
        Any ideas what I should do? I've searched my whole project,
        and nowhere does it seem to reference libc.lib (obviously I
        can't check in the lib file because it is compiled and I do not
        have access to the source code).
        I think that this means that the static library that you need specifies a
        version of the runtime different from the one that you are using in the rest
        of the project.

        Try this: Go to the Linker Settings in your project's configuration. Choose
        Input. In the text box labeled "Ignore Specific Library" enter

        libc.lib

        Relink.

        Regards,
        Will


        Comment

        • robintw

          #5
          Re: Unresolved Externals errors when using external .l ...

          Hi,

          Thanks for the suggestion. I have tried that and now get the following linker errors:

          LNK2019: unresolved external symbol __imp__RegClose Key@4 referenced in function _DigiLogicalOpe n

          LNK2019: unresolved external symbol __imp__RegQuery ValueExA@24 referenced in function _DigiLogicalOpe n

          LNK2019: unresolved external symbol __imp__RegOpenK eyExA@20 referenced in function _DigiLogicalOpe n

          I am pretty sure that the function DigiLogicalOpen is in the qhdlc.lib file - but is not one of the publically accessible functions from that file.

          You say that maybe the library was compiled using a different version of the library - well, as far as I know, the library was compiled with a standard ANSI C compiler, not using anything .Net related at all.

          Hope that helps, and thanks for the help,

          Robin
          ---
          Posted via DotNetSlackers. com

          Comment

          • Carl Daniel [VC++ MVP]

            #6
            Re: Unresolved Externals errors when using external .l ...

            robintw wrote:
            Hi,
            >
            Thanks for the suggestion. I have tried that and now get the
            following linker errors:
            >
            LNK2019: unresolved external symbol __imp__RegClose Key@4 referenced
            in function _DigiLogicalOpe n
            >
            LNK2019: unresolved external symbol __imp__RegQuery ValueExA@24
            referenced in function _DigiLogicalOpe n
            >
            LNK2019: unresolved external symbol __imp__RegOpenK eyExA@20
            referenced in function _DigiLogicalOpe n
            >
            I am pretty sure that the function DigiLogicalOpen is in the
            qhdlc.lib file - but is not one of the publically accessible
            functions from that file.
            >
            You say that maybe the library was compiled using a different version
            of the library - well, as far as I know, the library was compiled
            with a standard ANSI C compiler, not using anything .Net related at
            all.
            I looks like you need to add ADVAPI32.LIB to your linker inputs. That's
            where RegCloseKey et al are decalred.

            -cd


            Comment

            • William DePalo [MVP VC++]

              #7
              Re: Unresolved Externals errors when using external .l ...

              <robintwwrote in message news:Ort96doAHH A.204@TK2MSFTNG P04.phx.gbl...
              I am pretty sure that the function DigiLogicalOpen is in
              the qhdlc.lib file - but is not one of the publically accessible
              functions from that file.
              Carl's suggestion is likely to get you over the last hurdle.
              You say that maybe the library was compiled using a different
              version of the library - well, as far as I know, the library was
              compiled with a standard ANSI C compiler, not using anything
              .Net related at all.
              Well, there is not a single version of the library. There are several of
              them. They differ as to whether they are implemented in a DLL or not,
              whether they support multithreading or not, whether they have debug
              information or not, etc.

              The authors of your static library preferred one runtime, your project
              requires another. I helped you tell the linker to ignore the static
              library's preferred runtime.
              ... and thanks for the help,
              You are welcome.

              Regards,
              Will


              Comment

              Working...