更新时间:2022-10-15 17:34:32
The best is not to disable (i.e. ignore) the linker warning, but fix the issue that the linker is prompting: the LNK4049 warning means that you have declare something as__declspec(dllexport)
inside a module of your project, and as__declspec(dllimport)
on another module of the same project.
If what you want is to reference something that you have instantiated on another module (i.e. another.c
or.cpp
file), simply declare it usingextern
.
If you really need to import or export that symbol to/from another executable, you should declare the symbol with the same linkage on both your modules (i.e. or as__declspec(dllexport)
on both, or as__declspec(dllimport)
on both).
Instead of using__declspec(dllimport)
and__declspec(dllexport)
in header file, which would (most probably) be common for both DLL and the EXE (or another DLL); you can define a common macro:#ifdef DLL_PROJECT #define IMPORT_EXPORT __declspec(dllexport) #else #define IMPORT_EXPORT __declspec(dllimport) #endif
For the you need to defineDLL_PROJECT
in DLL project. You should name this macro to something meaningful, likeMP3CODEC_DLL
, so that it doesn''t *** with some other projects/header files:#ifdef MP3CODEC_DLL #define CODEC_IMPORT_EXPORT __declspec(dllexport) #else #define CODEC_IMPORT_EXPORT __declspec(dllimport) #endif</pre>And then use
CODEC_IMPORT_EXPORT
in your header file.
See here[^].