0

I has core dll library called Lib1, I has main application that depends on Lib1 and another extension dll library called POS, It also depend on Lib1, I add the Lib1 as in the references of the project properties, it see the .lib automatically. I added the following .h and .cpp files to the Lib1

//MenuBarEx.h
class AMNLIB1_API TMenuBarEx : public CMFCMenuBar
{
    DECLARE_DYNAMIC(TMenuBarEx)
    public:
    TMenuBarEx()
    {
        NONCLIENTMETRICS ncm;
        ncm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(ncm.iPaddedBorderWidth); 
        ZeroMemory(&m_logFont, sizeof(LOGFONT));

        if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
        {
            m_logFont = ncm.lfMenuFont;
            TCHAR fontName[] = _T("tahoma");
            _tcscpy_s(m_logFont.lfFaceName, fontName);
            CMFCMenuBar::SetMenuFont(&m_logFont);
        }
    }
    virtual ~TMenuBarEx()
    {

    }
    BOOL LoadState(LPCTSTR lpszProfileName /* = NULL */, int nIndex /* = -1 */, UINT uiID /* = */ )
    {
        return TRUE;
    }
    BOOL SaveState(LPCTSTR lpszProfileName /* = NULL */, int nIndex /* = -1 */, UINT uiID /* = */ )
    {
        return TRUE;
    }
protected:
    static LOGFONT m_logFont;
    //DECLARE_MESSAGE_MAP()
};
//-------------------------------------------
//.cpp
#include "stdafx.h" // precompiled header
#include "MenuBarEx.h"

IMPLEMENT_DYNAMIC(TMenuBarEx, CMFCMenuBar)
LOGFONT TMenuBarEx::m_logFont;

The Lib1 build successfully and the main application that uses the class TMenuBarEx also build successfully, the library POS fail in build giving the error

POSMain.obj : error LNK2001: unresolved external symbol "protected: static struct tagLOGFONTA TMenuBarEx::m_logFont" (?m_logFont@TMenuBarEx@@1UtagLOGFONTA@@A)

this is really strange because it is defined in the cpp and worked in the main application, and many other extension libraries are using the core Lib1 and build successfully.

when I want to pass through this I redefine it again in the POSMain.cpp this is so bad but I do it to finish the release How can I fix it or even track it???

ahmedsafan86
  • 1,776
  • 1
  • 26
  • 49
  • Did you add the lib file to the POS project? – o_weisman Feb 11 '14 at 13:56
  • @o_weisman : I add it using the Properties->Common Properties->Framework and References ->Add new reference, then I added the Lib1 project now the project recognize the .lib and its full path. I use Lib1 in the main application the same way – ahmedsafan86 Feb 11 '14 at 14:13
  • Note the structure name: tagLOGFONTA. Some odds that you have a tagLOGFONTW. You have to make sure that the General + Character Set setting for all the projects is the same. – Hans Passant Feb 11 '14 at 14:32
  • it is all the same all of it is multibyte right now we have a plane for moving to unicode. all of the dlls and are multibyte. the POS depend on Lib1 and using many things our string type TString that inherits from CString is in Lib1 it is the core of the application only the static members has problem only in this project POS, this is really crazy. – ahmedsafan86 Feb 11 '14 at 14:36
  • Use Dependency Walker or dumpbin to find out the decorated name that `m_logFont` member got exported under. Compare it with the name the linker complains about; the difference often proves illuminating. – Igor Tandetnik Feb 11 '14 at 14:44
  • @IgorTandetnik:I mentioned that it is used the library in the main application so no need to look in dependency walker, however I looked in the dependency walker and copied all the exported items to a notepad and searched for it and it is already exported, and by the way the POS library not involved and has no deal with that class at all I just added it to Lib1 and used it in main application and recompiled the solution thats it. – ahmedsafan86 Feb 11 '14 at 16:07
  • @ahmedsafan86 What VS are you using? Is Lib1 compiled as a .dll file? If so, why do you need the .lib file for it? (if you are relying on the .lib file, I think you need to also add its directory in the Additional Library Directories under Linker->General in project properties) Are the code generation options for both Lib1 and POS projects compatible (Multithreaded debug / Debug etc.)? Is the usage method of MFC (static/dynamic) the same in both projects? – o_weisman Feb 12 '14 at 10:01
  • @o_weisman: do you understand what the meaning of add reference to a project, that I mentioned before?? also the .lib not only used for static linking also for the dynamic linking if you are exporting any symbols from your dll a .lib file is generated for the linking in case you imported those exported symbols. they are all using same runtime libraries its all ok the build succeed if there is no static member in the class, in that project only. – ahmedsafan86 Feb 12 '14 at 19:55
  • @ahmedsafan86 Found you a previous response that addresses your problem: http://stackoverflow.com/questions/2479784/exporting-static-data-in-a-dll – o_weisman Feb 13 '14 at 10:11

0 Answers0