MFC工程中使用sqlite3源代码--c和c++代码混合编译出错解决

前端之家收集整理的这篇文章主要介绍了MFC工程中使用sqlite3源代码--c和c++代码混合编译出错解决前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

网上下载的sqlite3现成的dll是win32位的,而由于我正在写的程序是64位的,所以将网上下的sqlite3的源代码直接加载到工程中使用了。

最新版本的sqlite3源文件只有一个.h和.c文件,比以前用起来方便多了。

在这2个文件的Property -> c/c++ -> Precompiled Headers 中设置为Not UsingPrecompiled Headers并build后,出现了4个错误

1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) already defined in LIBCMTD.lib(new.obj)
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPEAX@Z) already defined in LIBCMTD.lib(dbgdel.obj)
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) already defined in LIBCMTD.lib(new2.obj)
1>uafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) already defined in LIBCMTD.lib(delete2.obj)
fatal error LNK1169: one or more multiply defined symbols found


这个应该是c和c++在编译的时候调用了不同的类库导致的冲突。在google及msdn一番以后,在msdn中找到了解决方法

Linker Tools Error LNK1169

The build Failed due to multiple definitions of one or more symbols. This error is preceded by error LNK2005.

The /FORCE or /FORCE:MULTIPLE option overrides this error.


于是在project -> Properties-> Linker -> Command Line中添加 /force命令,重新build后就变成:

1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/FORCE' specification
1>uafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) already defined in LIBCMTD.lib(new.obj); second definition ignored
1>uafxcwd.lib(afxmem.obj) : warning LNK4006: "void __cdecl operator delete(void *)" (??3@YAXPEAX@Z) already defined in LIBCMTD.lib(dbgdel.obj); second definition ignored
1>uafxcwd.lib(afxmem.obj) : warning LNK4006: "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) already defined in LIBCMTD.lib(new2.obj); second definition ignored
1>uafxcwd.lib(afxmem.obj) : warning LNK4006: "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) already defined in LIBCMTD.lib(delete2.obj); second definition ignored
1>warning LNK4088: image being generated due to /FORCE option; image may not run

之前的error变成了warning。程序也能编译通过正常运行了。至于忽略这些错误后会有什么影响等将来还会进行测试跟踪。至少目前建立数据库文件和建立新表等操作都是正常的。

原文链接:https://www.f2er.com/sqlite/202582.html

猜你在找的Sqlite相关文章