一个 C 的 . LIB 文件 在 c++ 中调用的问题
用c 写了这么个.LIB
#include "stdlib.h "
#include "stdio.h "
#ifdef __cplusplus
extern "C " {
#endif
typedefstruct _LogFile{
FILE* pFile;
}LOGFILE,*LPLOGFILE;
#ifndef WINAPI
#define WINAPI __stdcall
#endif
int WINAPI InitLog(const char* pszStr);
int WINAPI UnInitLog();
#ifdef __cplusplus
}
#endif
我在 vc 用 控制台 来连接 就没有问题 , 在其他 如 dll, windows application 下 就有问题 了
estdll1.cpp
Linking...
libc.lib(crt0dat.obj) : error LNK2005: __cinit already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: _exit already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __exit already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __cexit already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __c_exit already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __C_Exit_Done already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __C_Termination_Done already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __exitflag already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __wpgmptr already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __pgmptr already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___winitenv already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __wenviron already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___initenv already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __environ already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___wargv already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___argv already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: ___argc already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winminor already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winmajor already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __winver already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __osver already defined in LIBCMTD.lib(crt0dat.obj)
libc.lib(crt0dat.obj) : error LNK2005: __umaskval already defined in LIBCMTD.lib(crt0dat.obj)
[解决办法]
调整工程选项来解决。
[解决办法]
修改 C/C++ Code generation.run-time library
[解决办法]
Try to set 'Using MFC Share DLL ' in project settings of the windows application. If not successful, try to remove 'LIBCMTD.lib ' from link option of the windows application.
[解决办法]
LNK2005: <some-long-string-of-mostly-garbage> already defined in <name> .lib( <name> .obj)
This error usually results from including a source code file multiple times. If you recognize any of the names in the message then it probably results from multiple inclusion of one of your own header files. Check to be sure that you 've used #ifndef/#define/#endif properly your header files. If you don 't recognize the name then it 's probably multiple inclusion of a system file (e.g., afxwin.h). Make sure that you haven 't explicitly included something in main.cpp that is already included in one of your own header files. Also check that you haven 't #i ncluded a .cpp file where you should have #i ncluded a .h file.