【发布时间】:2011-12-25 04:52:26
【问题描述】:
大家圣诞快乐。
昨天我下载了 Boost 库。我使用 CodeBlocks(使用 Mingw32 gcc V4.4.1) 编译它。 bjam 命令行是: bjam install --toolset=gcc--prefix="C:\zjc\PluginFramework\boost_1_42_0" --build-type=complete. 它是成功的。 我想测试图书馆。我写了一些代码如下:
#include <stdlib.h>
#include <iostream>
using std::cout;
using std::wcout;
using std::endl;
#include <string>
using std::string;
using std::wstring;
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/format.hpp>
int main(int argc, char* argv[])
{
// ANSI character format
cout << boost::format( "%1% %2%" ) % "Hell" % "Low" <<endl;
string s1 = boost::str( boost::format( "%2% %1%" ) % "Hell" % "Low" );
cout << s1 << endl;
// UNICODE character format
wcout << boost::wformat( L"%s %X" ) % L"-1 is" % -1 << endl;
wstring s2 = boost::str( boost::wformat( L"%2$s %1$.2f" ) % 3.141592 % L"Version" );
wcout << s2 << endl;
// get the path of application(ANSI character set), note:boost::filesystem::path
string AnsiPath = boost::filesystem::initial_path<boost::filesystem::path>().string();
cout<<AnsiPath<<endl;
// get the path of application(unicode character set), note:boost::filesystem::wpath
wstring UnicodePath = boost::filesystem::initial_path<boost::filesystem::wpath>().string();
wcout<<UnicodePath<<endl;
system("PAUSE");
return 0;
}
出现一个编译错误:obj\Debug\main.o:C:\zjc\PluginFramework\boost_1_42_0\include\boost-1_42\boost\filesystem\operations.hpp|530|undefined reference to `boost::filesystem: :detail::get_current_path_api(std::string&)'| 我在链接器选项中添加了库:
boost_system-mgw44-mt-d-1_42.lib
libboost_system-mgw44-sd-1_42.lib
boost_system-mgw44-d.lib
boost_system-mgw44-d-1_42.lib
boost_system-mgw44-mt-d-1_42.lib
宏:
BOOST_ALL_DYN_LINK
BOOST_SYSTEM_NO_LIB
BOOST_SYSTEM_NO_DEPRECATED
_调试
_控制台
BOOST_FILESYSTEM_VERSION
BOOST_FILESYSTEM_DYN_LINK
BOOST_LIB_DIAGNOSTIC
我在互联网上搜索。解决方案是链接 boost 文件系统库。但我已经链接了库。我的环境:Win 7 Home 版本,Code::Blocks V 10.05。
【问题讨论】: