Pedro Soares
Pedro Soares

Reputation: 1195

Symbols in lib not being included

I have been updating a big working C++ Windows application in Visual Studio 2022 into several static libs. The idea is to share part of the code to an external developer, and not share the complete C++ files of the project. Only part of the code would be shared, and the rest would be .lib's and .h's.

The structure of the entire solution is:

When building the application EXE, the link fails with thousands of errors of missing symbols from the External LIB. "LNK2001 unresolved external symbol "__declspec(dllimport) public: bool __thiscall ..."

1>Common.lib(LocalizedString.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall cocos2d::Value::isNull(void)const " (__imp_?isNull@Value@cocos2d@@QBE_NXZ)
1>  Hint on symbols that are defined and could potentially match:
1>    "__declspec(dllimport) public: bool __thiscall cocos2d::Data::isNull(void)const " (__imp_?isNull@Data@cocos2d@@QBE_NXZ)

The EXE is configured to include all the libs (configured in VS project settings: Additional Dependencies). All the projects are being built with __cdecl (/Gd) and Multi-threaded Debug DLL (/MDd).

If I add to the EXE code some dummy declarations of symbols that are being referred into the "unresolved external symbol" error, Visual Studio adds those symbols and I can see the number of errors decreasing. But this is not a good solution... It looks like somehow Visual Studios is adding all the symbols automatically.

I believe this whole issue may be related with the following. When building my libs I get the following "warning LNK4006: XXXX already defined in XXXXX.lib(xxhash.obj); second definition ignored".

I have tried different project settings, like "Link Library Dependencies: Yes". But nothing seems to fix it.

I'm stuck with this for two days... Can someone save me?

Upvotes: 1

Views: 556

Answers (1)

Pedro Soares
Pedro Soares

Reputation: 1195

Found the problem. There was an hidden define in the external lib adding the dllimport to every external class.

#if defined(CC_STATIC)
    #define CC_DLL
#else
#if defined(_USRDLL)
    #define CC_DLL     __declspec(dllexport)
#else         /* use a DLL library */
    #define CC_DLL     __declspec(dllimport)
#endif
#endif

Upvotes: 1

Related Questions