关于boost::regex库+ICU的编译和使用

何哀何欢 2009-06-09 03:23:07
因为要分析utf8字串,所以要用ICU。并且要用到 多线程
环境 :VC2008(9.0)
icu 4.0 在 i:/icu 目录
boost 1.38

我用的是vc2008,先用ICU的 source\allinone\allinone.sln 在vc2008里编译

然后照网上说,拷贝多一份 icudt.lib 改为 icudata.lib icuin.lib 改为 icui18n.lib
因为bjam 要用到不同的名称。旧名称也还在,没删,因为nmake要用到

然后打开 vc9 的命令行控制台,用bjam在 boost_1_39_0\libs\regex\build 里使用

bjam -s HAVE_ICU=1 -s ICU_PATH=i:/icu threading=multi release link=shared runtime-link=shared

最后就在 boost_1_39_0\bin.v2\libs\regex\build\ 下找到lib 和 dll

最后,在vc2008里建立工程,设置相应目录


#define BOOST_HAS_ICU
#include <iostream>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>

//网上随便找的例子
std::string get_filename(const std::string& path)
{
boost::u32regex r = boost::make_u32regex("(?:\\A|.*\\\\)([^\\\\]+)");
boost::smatch what;
if(boost::u32regex_match(path, what, r))
{
// extract $1 as a CString:
return what.str(1);
}
else
{
throw std::runtime_error("Invalid pathname");
}
}

int _tmain(int argc, _TCHAR* argv[])
{
std::string str = get_filename("a123.bmp");
return 0;
}


但是连接错误:

Linking...
Test.obj : error LNK2001: unresolved external symbol _u_tolower_4_0

然后我加入:


#define BOOST_HAS_ICU
#include <iostream>
#include <boost/regex.hpp>
#include <boost/regex/icu.hpp>
#pragma comment(lib, "icuuc.lib")
#pragma comment(lib, "icuin.lib")
#pragma comment(lib, "icudt.lib")

//。。。


编译过了,但是运行抛异常,挂了:这行:


boost::u32regex r = boost::make_u32regex("(?:\\A|.*\\\\)([^\\\\]+)");



网上没人讨论过这情况。。。。。咋解决?
...全文
1062 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
狂妄Beyond 2010-10-14
  • 打赏
  • 举报
回复
学习中,望楼主早日解决疑问
pysjp 2009-06-10
  • 打赏
  • 举报
回复
学习中,望楼主早日解决疑问
老邓 2009-06-10
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 williamx 的回复:]
引用 2 楼 Loaden 的回复:
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared



什么意思?我的程序是vc2008编译的exe,不是lib/dll阿?
[/Quote]
确定你的程序使用的编译选项为/MD或/MDd
何哀何欢 2009-06-10
  • 打赏
  • 举报
回复
up
何哀何欢 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Loaden 的回复:]
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
[/Quote]

什么意思?我的程序是vc2008编译的exe,不是lib/dll阿?
老邓 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hikaliv 的回复:]
引用 4 楼 Loaden 的回复:
引用 3 楼 hikaliv 的回复:
引用 2 楼 Loaden 的回复:
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
呵,等你来呢……我早就看到这个了……
我的 boost 下调试没问题。


“等你来呢”:迷糊了...



等你来解答这个问题……你不是BOOST无敌么。
[/Quote]
我倒!我才用boost一年,而且regex我并没有过多涉及:很多时候都是现查boost文档的。
光宇广贞 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Loaden 的回复:]
引用 3 楼 hikaliv 的回复:
引用 2 楼 Loaden 的回复:
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
呵,等你来呢……我早就看到这个了……
我的 boost 下调试没问题。


“等你来呢”:迷糊了...

[/Quote]
等你来解答这个问题……你不是BOOST无敌么。
wanggang_0717 2009-06-09
  • 打赏
  • 举报
回复
up
老邓 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hikaliv 的回复:]
引用 2 楼 Loaden 的回复:
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
呵,等你来呢……我早就看到这个了……
我的 boost 下调试没问题。
[/Quote]
“等你来呢”:迷糊了...
光宇广贞 2009-06-09
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 Loaden 的回复:]
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
[/Quote]

呵,等你来呢……我早就看到这个了……
我的 boost 下调试没问题。
老邓 2009-06-09
  • 打赏
  • 举报
回复
另外,保证你当前程序与boost编译方式对应同样的runtime:runtime-link=shared
老邓 2009-06-09
  • 打赏
  • 举报
回复
不知道你的VS2008打了SP1没有。如果打了的话,可以使用std::tr1::regex试试

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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