Search code examples
mfcboost-threadstatic-linkingdynamic-linking

Upgrade of BOOST 1.35 to 1.43 causes linker error with __pRawDllMain (mfc related)


At work we have an MFC Extension DLL that built fine with 1.35 but when built with 1.43 causes the following error:

error LNK2005: __pRawDllMain already defined in ApObs.obj

If I activate BOOST_LIB_DIAGNOSTIC the old build lists:

linking to lib file: libboost_thread-vc71-mt-gd-1_35.lib

and

linking to lib file: libboost_thread-vc71-mt-gd-1_43.lib

So no change there with which library is linked

The full error message is:

libboost_thread-vc71-mt-gd-1_43.lib(tss_pe.obj) : error LNK2005: __pRawDllMain already defined in ApObs.obj

I have done a diff on tss_pe.cpp in both library versions and they are identical, so I'm not sure what the problem is.

You can get the message to disappear by defining BOOST_THREAD_USE_DLL but then we would need to ship BOOST_THREAD-VC71-MT-GD-1_43.DLL so I don't think this is the best solution.


Solution

  • This happens because of the linking order.
    You can change the linking error by manually adding the libs in the Additional Dependencies.
    In my case putting libboost_thread-vc71-mt-gd-1_43.lib BEFORE the other conflicting lib solved the problem:

    Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies

    libboost_thread-vc80-mt-1_40.lib;mfcs80u.lib;%(AdditionalDependencies)

    Note that in my case it was conflicting with mfcs80u.lib