boost库链接

ivy1023 2008-01-25 02:35:36
我想用boost库中的正则表达式,我用的是最网上那个最经典的例子,代码如下,为什么build的时候出现如下错误提示:
error C2018: unknown character '0xa1',请问下是为什么?

#include "stdafx.h"
#include <cstdlib>
#include <stdlib.h>
#include <boost/regex.hpp>
#include <string>
#include <iostream>

using namespace std;
using namespace boost;

regex expression("^select ([a-zA-Z]*) from ([a-zA-Z]*)");

int main(int argc, char* argv[])
{
 std::string in;
 cmatch what;
 cout << "enter test string" << endl;
 getline(cin,in);
 if(regex_match(in.c_str(), what, expression))
 {
  for(int i=0;i<what.size();i++)
   cout<<"str :"<<what[i].str()<<endl;
 }
 else
 {
  cout<<"Error Input"<<endl;
 }
 return 0;
}
...全文
740 29 打赏 收藏 转发到动态 举报
写回复
用AI写文章
29 条回复
切换为时间正序
请发表友善的回复…
发表回复
JaneThink 2011-03-03
  • 打赏
  • 举报
回复
"Error C2018: unknown character '0xa1'" 这种错误肯定是输入中文的字符。
volkswageos 2010-06-21
  • 打赏
  • 举报
回复
warning: STLPort debug versions are built with /D_STLP_DEBUG=1
d:\boost\include\boost-1_34_1\boost\config\auto_link.hpp(217) : fatal error C1189: #error : "Build options aren't compatible with pre-built libraries"
Error executing cl.exe.

我也是这个问题,怎么解决啊?
schlafen 2008-02-05
  • 打赏
  • 举报
回复
超经典的的问题和答复,我刚解决了这个问题。
ivy1023 2008-01-28
  • 打赏
  • 举报
回复
谢谢各位特别是calss_cyl & blusherbear,该问题得得到了解决。
关键问题还是我的环境的问题,开始时候是C 运行时候库冲突,后来是因为环境被污染,我重装安装环境后,该问题得到解决。
hzxhzx123 2008-01-28
  • 打赏
  • 举报
回复
C++的泛型编程中,需要把所有使用到泛型声明或者定义的代码都直接写在.h头文件中,不能写在.cpp文件中!

VC2005也还没有支持分离编译的export关键字!

模板类只能写在一个.h文件中。而且,不可以放在dll项目中。因为模板类是无法导出的!
导出以后的模板类,只能够在外部声明这个模板类,不能够实际创建模板类的对象!否则会报告
TestMain.obj : error LNK2019: 无法解析的外部符号"__declspec(dllimport) public: __thiscall net_sf_interfacecpp_core_lang::ObjectRefManage<class AClass>::ObjectRefManage<class AClass>(void)" (__imp_??0?$ObjectRefManage@VAClass@@@net_sf_interfacecpp_core_lang@@QAE@XZ),该符号在函数_main 中被引用
这样的错误。
因为,模板类实际上并没能编译成二进制代码。它只是一个宏!需要在编译时根据客户代码的使用情况生成源代码,然后再变成二进制代码。
因此,作为宏,它应该在.h文件中。作为源代码的元数据,应该共享给用户。因为它需要根据客户的使用情况来生成源代码。因此,它必须在最终客户代码一起!


我连这个解释也没完全看懂,貌似就是说boost和VS2005还不能完全的结合
calss_cyl 2008-01-28
  • 打赏
  • 举报
回复
你确认一下那些 *.lib 和*.dll是不是在一个文件夹里面的?应该是的。
然后按照我那两个设置一下Include 和 Library。
还有就是你可以新建那些 完全空的Project,然后把你自己的代码填进去看看编译成功不。
ivy1023 2008-01-26
  • 打赏
  • 举报
回复
在VC6下,我连接过了,运行通过。
但是在VC2003下,总是连接不过,提示信息如下:
代码:
#include "boost/regex.hpp"
#include <cstdlib>
#include <stdlib.h>
#include <string>
#include <iostream>

using namespace std;
using namespace boost;

int main()
{
regex ex("^select ([a-zA-Z]*) from ([a-zA-Z]*)");

return 0;
}

------ 已启动生成: 项目: sdsd, 配置: Debug Win32 ------

正在编译...
main.cpp
正在链接...
main.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall boost::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >::~reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >(void)" (__imp_??1?$reg_expression@DV?$regex_traits@D@boost@@V?$allocator@D@_STL@@@boost@@QAE@XZ) ,该符号在函数 _main 中被引用
main.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall boost::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >(char const *,unsigned int,class _STL::allocator<char> const &)" (__imp_??0?$reg_expression@DV?$regex_traits@D@boost@@V?$allocator@D@_STL@@@boost@@QAE@PBDIABV?$allocator@D@_STL@@@Z) ,该符号在函数 _main 中被引用
Debug/sdsd.exe : fatal error LNK1120: 2 个无法解析的外部命令

生成日志保存在“file://d:\practice\sdsd\Debug\BuildLog.htm”中
sdsd - 3 错误,0 警告


ivy1023 2008-01-26
  • 打赏
  • 举报
回复
谢谢blusherbear,用/FORCE:MULTIPLE命令解决了控制台程序链接不过的问题。
ivy1023 2008-01-26
  • 打赏
  • 举报
回复
自己顶一下,有哪位能给出建议吗?
ivy1023 2008-01-26
  • 打赏
  • 举报
回复
上面代码是auto_link.hpp中的一段
ivy1023 2008-01-26
  • 打赏
  • 举报
回复
我换了个版本现在用的是1.34.1,但是编译的时候通不过,其中出问题的代码是auto_link.hpp,代码为下面加粗的一行,说是我的build option 不对,我该改成什么样呢?
说明,我的库是build通过了,这是在工程中包含boost/regex.hpp后的编译情况。
#if defined(_MSC_VER) || defined(__MWERKS__)

# ifdef _DLL

# if (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) && (defined(_STLP_OWN_IOSTREAMS) || defined(__STL_OWN_IOSTREAMS))

# if defined(_DEBUG) && (defined(__STL_DEBUG) || defined(_STLP_DEBUG))
# define BOOST_LIB_RT_OPT "-gdp"
# elif defined(_DEBUG)
# define BOOST_LIB_RT_OPT "-gdp"
# pragma message("warning: STLPort debug versions are built with /D_STLP_DEBUG=1")
# error "Build options aren't compatible with pre-built libraries"
# else
# define BOOST_LIB_RT_OPT "-p"
# endif
blusherbear 2008-01-25
  • 打赏
  • 举报
回复
C RUNTIME LIBRARY冲突。
试试以下方法:
在项目属性设置页中,LINK(链接)页,在最后一个选项,高级命令行中加入 /FORCE:MULTIPLE。
更具体的说明请参见下面链接:
http://hi.baidu.com/winfred/blog/item/ecb9cbf9b02f435b252df2da.html
blusherbear 2008-01-25
  • 打赏
  • 举报
回复
C RUNTIME LIBRARY冲突。
试试以下方法:
在项目属性设置页中,LINK(链接)页,在“命令行”中加入 /FORCE:MULTIPLE
ivy1023 2008-01-25
  • 打赏
  • 举报
回复
build完后,就一个文件夹含 *.lib,我加上去了。但是不行啊。
而且我没有发现有stage\lib_v71目录,只有在build目录下,生成一个vc71目录啊。怎么回事?
我下的版本好象是:boost_1_34_1啊。难道有错?

如果不介意的话,把你下的版本传上来,我再试试?
calss_cyl 2008-01-25
  • 打赏
  • 举报
回复
搜索 *.lib ,只加那个 lib_v71 的文件夹,可能有一个lib_v60的,不用加。那个 Executable files目录 似乎不用加。那些*.lib 和*.dll都在一起的。
我这里只加了 Include目录和Library目录,我刚下载了一个正则表达式的例子,编译通过了。我的就这两个:
Include 要包含 C:\boost_1_33_1;
Libarary 要包含 C:\boost_1_33_1\stage\lib_v71 。
ivy1023 2008-01-25
  • 打赏
  • 举报
回复
to calss_cyl,
boost 库确认已经编译好了.
ivy1023 2008-01-25
  • 打赏
  • 举报
回复
to calss_cyl,

首先谢谢你的建议,我已经把boost库build出的*.lib所在的目录加到Library files下,又把*.dll目录放到Executable files目录下了。但是现在还是不行。是不是我加错了?
calss_cyl 2008-01-25
  • 打赏
  • 举报
回复
前提是你的boost是都编译好的啊。
calss_cyl 2008-01-25
  • 打赏
  • 举报
回复
VS2003里面,Tools -> Option 左边Projects->VC++ Directories ,
右边 的 右上角有下拉条里面有Library files,都设置对就行。
ivy1023 2008-01-25
  • 打赏
  • 举报
回复
对于6楼的build信息如下:

正在编译...
MyTest.cpp
正在链接...
MyTest.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall boost::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >(char const *,unsigned int,class _STL::allocator<char> const &)" (__imp_??0?$reg_expression@DV?$regex_traits@D@boost@@V?$allocator@D@_STL@@@boost@@QAE@PBDIABV?$allocator@D@_STL@@@Z) ,该符号在函数 _$E4 中被引用
MyTest.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: __thiscall boost::reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >::~reg_expression<char,class boost::regex_traits<char>,class _STL::allocator<char> >(void)" (__imp_??1?$reg_expression@DV?$regex_traits@D@boost@@V?$allocator@D@_STL@@@boost@@QAE@XZ) ,该符号在函数 _$E5 中被引用
Debug/MyTest.exe : fatal error LNK1120: 2 个无法解析的外部命令

生成日志保存在“file://d:\practice\MyTest\Debug\BuildLog.htm”中
MyTest - 3 错误,0 警告
加载更多回复(9)

64,651

社区成员

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

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