我写了一个静态库,文件如下:
lib.cpp#include <string>
using namespace std;
#include "lib.h"string mycode(char *pchSrc, int iSize)
{
string result;
........ return result;
}lib.h#ifndef __MYLIB__
#define __MYLIB__string mycode(char *pchSrc, int iSize);
#endif
然后写一个测试程序
包含文件如下:
#include <string>
using namespace std;
#include "lib.h"但是在编译连接的时候出现如下错误:
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_strin
g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in urllib.lib(urlcode.obj)
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/w32Test.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
请问入如何解决这个问题
lib.cpp#include <string>
using namespace std;
#include "lib.h"string mycode(char *pchSrc, int iSize)
{
string result;
........ return result;
}lib.h#ifndef __MYLIB__
#define __MYLIB__string mycode(char *pchSrc, int iSize);
#endif
然后写一个测试程序
包含文件如下:
#include <string>
using namespace std;
#include "lib.h"但是在编译连接的时候出现如下错误:
msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?$basic_strin
g@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in urllib.lib(urlcode.obj)
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/w32Test.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
请问入如何解决这个问题
解决方案 »
- 难道真的没有办法从外部中断线程且不造成资源泄漏?
- 一个XML的小问题
- 小弟,求教各位大哥,关于窗口的问题
- mdi程序中,如何在关闭子view窗口时弹出保存对话框
- 应该是很简单的,但我不知道怎么做。工具栏问题,在线结贴。
- 请教:m_fLogfile.Read(pBuffer , sizeof(VNumAndPassWord)); 错在哪?
- 求助ActiveX全屏显示问题
- filedisk功能扩展,如何添加挂载验证功能?
- 移位操作
- 如何通过MFC输入数据到网页js控件的文本框,并把返回的数据呈现在编辑框中
- 请问在 win98 下如何绑定 110 端口? 为什么我调用 bind 的时候提示错误,应该怎么解决?
- 我的问题再加50分,急死人啊!在线等待!
lib.cpp中有定义
#include <string>
using namespace std;
#include "lib.h"然后写一个测试程序
包含文件如下:
#include <string>
using namespace std;
#include "lib.h"
测试文件中也有using namespace std;。最好把using namespace std;声明在头文件中。
如
#ifndef __MYLIB__
#define __MYLIB__
using namespace std; //在lib.h中定义
string mycode(char *pchSrc, int iSize);
#endifstd是一个全局变量,编译器在命名中会因为重复定义出错
ghtsao(月之暗面):我试过两位的方法,不行。顺便纠正一点:std不是变量,是名字空间
但是我找不到解决的办法,请大家帮帮忙。
改成#include <string.h>
试试
#define __MYLIB__string mycode(char *pchSrc, int iSize);
#endif// 修改:
extern string mycode(char *pchSrc, int iSize);
你的方法我试过,不行啊。ruihuahan(飞不起来的笨鸟):
urllib.lib是我写的静态库的名字,怎么可以忽略呢?
不明白请说明白点错误很明显,好像string等一些标准库中的东西重复呢,但是我在静态库要引用一些标准库中的东西,该怎么做好?
这个错误的意思是link不兼容库。MSDN 原文:
Linker Tools Warning LNK4098
defaultlib "library" conflicts with use of other libs; use /NODEFAULTLIB:libraryYou are trying to link with incompatible libraries.