如何禁用LNK4049错误警告? [英] how to disable LNK4049 error warning?

查看:374
本文介绍了如何禁用LNK4049错误警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用LNK4049错误警告? : LNK4049 警告表示您已在项目的一个模块中将某些内容声明为__declspec(dllexport),并在同一项目的另一个模块中将其声明为__declspec(dllimport).

如果要引用在另一个模块上已实例化的内容(即另一个.c.cpp文件),只需使用extern进行声明即可.

如果确实需要将该符号导入另一个可执行文件或从另一个可执行文件导入该符号,则应在两个模块上声明具有相同链接的符号(即,两个模块上均为__declspec(dllexport)或两个模块上均为__declspec(dllimport)).


而不是在头文件中使用__declspec(dllimport)__declspec(dllexport),这(很可能)对于DLL和EXE(或另一个DLL)都是通用的;您可以定义一个通用宏:

#ifdef DLL_PROJECT
#define IMPORT_EXPORT __declspec(dllexport)
#else
#define IMPORT_EXPORT __declspec(dllimport)
#endif



对于您,您需要在DLL项目中定义DLL_PROJECT.您应该将此宏命名为有意义的名称,例如MP3CODEC_DLL,以免与其他项目/头文件发生冲突:

#ifdef MP3CODEC_DLL
#define CODEC_IMPORT_EXPORT __declspec(dllexport)
#else
#define CODEC_IMPORT_EXPORT __declspec(dllimport)
#endif</pre>

,然后在头文件中使用CODEC_IMPORT_EXPORT.


请参阅^ ].


how to disable LNK4049 error warning?

解决方案

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 using extern.

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 define DLL_PROJECT in DLL project. You should name this macro to something meaningful, like MP3CODEC_DLL, so that it doesn''t clash 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[^].


这篇关于如何禁用LNK4049错误警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆