求助:用boost:regex时链接出错

astrophor 2007-04-06 11:20:35
程序是书上的例子:
#include <iostream>
#include <cassert>
#include <string>
#include "boost/regex.hpp"

int main() {
boost::regex reg("\\d{3}([a-zA-Z]+).(\\d{2}|N/A)\\s\\1");

std::string correct="123Hello N/A Hello";
std::string incorrect="123Hello 12 hello";

assert(boost::regex_match(correct,reg)==true);
assert(boost::regex_match(incorrect,reg)==false);
system("pause") ;
return 0 ;
}

编译时出现链接错误:
F:\test1\Debug\test(.text$_ZN5boost11basic_regexIcNS_12regex_traitsIcEESaIcEED1Ev+0xd): In function `ZN5boost9re_detail11saved_stateC2Ej':
D:\Program files\boost\boost\regex\v4\perl_matcher.hpp: undefined reference to `boost::reg_expression<char, boost::regex_traits<char>, std::allocator<char> >::~reg_expression()'
太多,这个只是一部分。

编译用到像shared_ptr不需要链接的都可以通过,但是如果需要链接的就不行
是什么原因?
我的lib文件夹下都是bjam运行后全部的.lib和.dll文件,debug和release的都有,版本号也有,编译器用dev和mingw都试过,都试这个问题。


...全文
574 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
JaneThink 2011-03-03
  • 打赏
  • 举报
回复
同样的问题,不过是连接错误:public: __thiscall boost::reg_expression<char,class boost::regex_traits<char>,class std::allocator<char> >
顶一下
roger_77 2007-04-13
  • 打赏
  • 举报
回复
lib问题

在dev-c++中使用boost应该指定编译器为:mingw,而不是GCC
这是有区别的
astrophor 2007-04-12
  • 打赏
  • 举报
回复
再顶下
foochow 2007-04-09
  • 打赏
  • 举报
回复
有可能你没链接到正确的库吧。。。
foochow 2007-04-09
  • 打赏
  • 举报
回复
代码没问题啊,VC6正常。。。
astrophor 2007-04-09
  • 打赏
  • 举报
回复
顶下
astrophor 2007-04-09
  • 打赏
  • 举报
回复
代码是书上的,没问题
是我安装boost的问题,我的bjam是从sourceforge上下的
用gcc编译,bjam -sTOOLS=gcc install
完成后在c盘有个boost文件夹,我把dev-c工具里的include和lib路径都添加这个了
可还是不能编译上面的那个程序
有谁遇到过类似的问题么,怎么解决
dsniff 2007-04-07
  • 打赏
  • 举报
回复
看飙了,不好意思……
估计是编译问题,VS03下无误
dsniff 2007-04-07
  • 打赏
  • 举报
回复
using namespace boost;
using namespace std;
freshui 2007-04-06
  • 打赏
  • 举报
回复
不懂 帮定下 不久我也要学这个
不想低调 2007-04-06
  • 打赏
  • 举报
回复
帮顶
  • 打赏
  • 举报
回复
你编译过regex库么?
看样子你需要将lib 和dll之类的文件放到lib目录里面

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧