locked
Linking a DLL from a DLL RRS feed

  • Question

  • I have serious problems with linking to another C++ library.
    My wrapper lib should dynamically link to other two libraries and use their functions as its own.

    Wrapper sees other lib's headers and they're located in the same solution but when I use other libs methods it shows me unresolved external symbol for those methods (just like I would not link to a lib object).

    My question is how to solve this issue?
    I have never referenced self-created library from another library and I followed this article.
    I don't have a Environment in Property Pages > Configuration properties > Debugging because I'm doing this in dll not a console application.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Tuesday, September 15, 2009 10:29 AM

Answers

  • Ok, sorry - I'm stupid :). I was trying to call methods from lib where there was no class name next to method names. So the complier showed me a right thing.

    I'm tired and didn't saw such an obvious thing.
    Thanks for help Shaihi.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    • Marked as answer by Mal Loth Tuesday, September 15, 2009 12:27 PM
    Tuesday, September 15, 2009 12:27 PM

All replies

  • In VS2005 at least, you go to Project-> properties->linker->input-> add the library to Additional dependencies.
    If this is a SOURCES files project then you need to add the libraries you depend on in the TARGETLIBS tag.

    Hope this is what you are looking for,
    Shai
    Tuesday, September 15, 2009 10:56 AM
  • Ok, now I got two questions:

    1) Where exacly in those PropertyPages should I add this TARGETLIBS?

    2) After Rebuilding the solution my ref library is not producing .lib file. Do You know what can be the problem?

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Tuesday, September 15, 2009 11:06 AM
  • My build log looks like this:

    Creating temporary file "c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008B18041264.rsp" with contents
    [
    /O2 /Os /D "NDEBUG" /D "_WIN32_WCE=0x420" /D "UNDER_CE" /D "WIN32_PLATFORM_PSPC" /D "WINCE" /D "_WINDOWS" /D "_USRDLL" /D "MICROSOFTSTACK_EXPORTS" /D "ARM" /D "_ARM_" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /FD /EHsc /MT /fp:fast /GR- /Yu"stdafx.h" /Fp"Pocket PC 2003 (ARMV4)\Release/MicrosoftStack.pch" /Fo"Pocket PC 2003 (ARMV4)\Release/" /Fd"Pocket PC 2003 (ARMV4)\Release/vc80.pdb" /W3 /c /Zi /TP

    ".\MSBluetooth.cpp"

    ".\MicrosoftStack.cpp"
    ]
    Creating command line "cl.exe @"c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008B18041264.rsp" /nologo"
    Creating temporary file "c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008C18041264.rsp" with contents
    [
    /O2 /Os /D "NDEBUG" /D "_WIN32_WCE=0x420" /D "UNDER_CE" /D "WIN32_PLATFORM_PSPC" /D "WINCE" /D "_WINDOWS" /D "_USRDLL" /D "MICROSOFTSTACK_EXPORTS" /D "ARM" /D "_ARM_" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /FD /EHsc /MT /fp:fast /GR- /Yc"stdafx.h" /Fp"Pocket PC 2003 (ARMV4)\Release/MicrosoftStack.pch" /Fo"Pocket PC 2003 (ARMV4)\Release/" /Fd"Pocket PC 2003 (ARMV4)\Release/vc80.pdb" /W3 /c /Zi /TP

    ".\stdafx.cpp"
    ]
    Creating command line "cl.exe @"c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008C18041264.rsp" /nologo"
    Creating temporary file "c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008D18041264.rsp" with contents
    [
    /OUT:"Pocket PC 2003 (ARMV4)\Release/MicrosoftStack.dll" /INCREMENTAL:NO /DLL /MANIFEST:NO /NODEFAULTLIB:"oldnames.lib" /DEBUG /PDB:"Pocket PC 2003 (ARMV4)\Release/MicrosoftStack.pdb" /STACK:65536,4096 /OPT:REF /OPT:ICF /DYNAMICBASE:NO /IMPLIB:"Pocket PC 2003 (ARMV4)\Release/MicrosoftStack.lib"  /subsystem:windowsce,4.20 /machine:ARM /ARMPADCODE Ws2.lib bthutil.lib bthguid.lib coredll.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib

    ".\Pocket PC 2003 (ARMV4)\Release\MicrosoftStack.obj"

    ".\Pocket PC 2003 (ARMV4)\Release\stdafx.obj"

    ".\Pocket PC 2003 (ARMV4)\Release\MSBluetooth.obj"
    ]
    Creating command line "link.exe @"c:\Documents and Settings\woj\Moje dokumenty\Visual Studio 2008\Projects\MicrosoftStack\MicrosoftStack\Pocket PC 2003 (ARMV4)\Release\RSP00008D18041264.rsp" /NOLOGO /ERRORREPORT:PROMPT"
     Output Window      Compiling...
    stdafx.cpp
    Compiling...
    MSBluetooth.cpp
    MicrosoftStack.cpp
    Generating Code...
    Linking...
     
    But it just doesn't produce MicrosoftStack.lib.
    What can be the problem?

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Tuesday, September 15, 2009 11:16 AM
  • My remark regarding TARGETLIBS does not concern your case. It refers to projects such as in Windows CE (subprojects) or drivers when an OEM develops the BSP. So forget that.

    Regarding the /IMPLIB flag, from reading http://msdn.microsoft.com/en-us/library/67wc07b9%28VS.80%29.aspx (without going too deep in) it says that if you don't have an EXPORT file then it does not create a lib and there is a link there to read about Lib creation. I never created a static lib using a project. I develop BSP rather than applications/libraries.
    Can you describe what exactly you are trying to do? Meaning what libs (by name) is linked against what and which lib you trying to create.

    Shai

    Tuesday, September 15, 2009 11:36 AM
  • I'm having two libs (will be three, but I'm learning now): wrapper.dll and MicrosoftStack.dll - both c++. Wrapper uses methods from MicrosoftStack.dll. I've created a new project (wrapper.dll) where I referenced MicrosoftStack.dll project and set Aditional Include Directories to a MicrosoftStack.dll directory (so that wrapper.dll will see its headers).

    Now the problem is: when I use something like this -> MicrosoftStack::MicrosoftStack::Init(), compilator says uneferenced external symbol MicrosoftStack::MicrosoftStack::Init().

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    Tuesday, September 15, 2009 11:44 AM
  • OK,
    You describe 2 dynamic libraries (Dll's). One should call methods from the other during run time.
    If this is the case, you need to load the Dll (using LoadLibrary) and get a pointer to your desired function (read http://msdn.microsoft.com/en-us/library/aa909187.aspx ). In this case you don't need to statically link against any library because all loading is done during run time.

    If you want to create a static library that you can link against then you should use what I stated in my previous post.

    Did this make sense?

    Shai
    Tuesday, September 15, 2009 12:20 PM
  • Ok, sorry - I'm stupid :). I was trying to call methods from lib where there was no class name next to method names. So the complier showed me a right thing.

    I'm tired and didn't saw such an obvious thing.
    Thanks for help Shaihi.

    If You'll find my answer satisfactory or helpful - mark it as answered or vote for it! Thank You.
    "If You think You know better then me, why is Your code not working, then don't waste my time at this forum. Otherwise - do as I'm suggesting."
    • Marked as answer by Mal Loth Tuesday, September 15, 2009 12:27 PM
    Tuesday, September 15, 2009 12:27 PM