【问题标题】:undefined reference to `boost::filesystem::detail::get_current_path_api(std::str未定义引用`boost::filesystem::detail::get_current_path_api(std::str
【发布时间】: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。

【问题讨论】:

    标签: c++ reference undefined


    【解决方案1】:

    Boost 文件系统库是包含的可链接(而不是仅标头)库之一。只需在“boost_system”之前添加“boost_filesystem”即可。

    如果一切设置正确,您就不必自己添加库: 不要设置BOOST_SYSTEM_NO_LIB/BOOST_FILESYSTEM_NO_LIB,除非你真的必须这样做。如果未设置,则标头应为您处理依赖项。

    带有BOOST_..._DYN_LINK 的宏将导致标头尝试链接共享库(您已使用其他宏停用了该库)。

    还有一点需要注意:如果您想手动添加库。不要混合它们,只添加一个你需要的变体,然后选择正确的一个(例如多线程调试“mt-d”)。

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-07
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多