Что является лучшим способом устранить Компоновщика Visual C++ MS, предупреждающего: “предупреждая LNK4221”?

Я не уверен, может ли это или нет, но Вы посмотрели Microsoft Network Monitor ? Это могло бы быть опцией.

17
задан Adisak 30 November 2009 в 22:44
поделиться

2 ответа

OK, the fix I am going to use is Pavel's suggestion with a minor tweak. The reason I’m using this fix is it’s an easy macro to drop in and it will work in bulk-builds / unity-builds as well as normal builds:

Shared Header:

// The following macro "NoEmptyFile()" can be put into a file
// in order suppress the MS Visual C++ Linker warning 4221
//
// warning LNK4221: no public symbols found; archive member will be inaccessible
//
// This warning occurs on PC and XBOX when a file compiles out completely
// has no externally visible symbols which may be dependant on configuration
// #defines and options.

#define NoEmptyFile()   namespace { char NoEmptyFileDummy##__LINE__; }

File that may compile out completely:

NoEmptyFile()
#if DEBUG_OPTION
      // code
#endif // DEBUG_OPTION
12
ответ дан 30 November 2019 в 12:13
поделиться

Use an anonymous namespace:

namespace { char dummy; };

Symbols within such namespace have external linkage, so there will be something in the export table. On the other hand, the namespace name itself will be distinct (you can think of it as "randomly generated") for every translation unit, so no clashes.

20
ответ дан 30 November 2019 в 12:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: