【问题标题】:Mac/Eclipse CDT: How to install boostMac/Eclipse CDT:如何安装 boost
【发布时间】:2016-06-20 18:43:24
【问题描述】:

Mac (El Capitan)/Eclipse CDT/boost:x86_64 架构的未定义符号

一个初学者的问题:

#include <iostream>
#include <boost/locale.hpp>

int main(void) {
        boost::locale::generator gen;
                    std::locale loc=gen("");
                    std::locale::global(loc);
                    std::cout.imbue(loc);
                    std::cout <<boost::locale::format("Today {1,date} at {1,time} we had run our first localization example") % time(0)
                          <<std::endl;
}

在 Eclipse 中构建此代码时,我得到:

    Invoking: MacOS X C++ Linker
    /usr/local/bin/g++-5 -L/Users/sam/boost_1_60_0/stage/lib -o "cpp-test-1"  ./calc-1.o ./test-1.o   
    Undefined symbols for architecture x86_64:
    "boost::locale::base_message_format<char>::id", referenced from: ...

关于此错误还有其他一些关于 SO 的问题。据我了解,问题是由编译器和 boost 库使用的不同标准库(libc++ 和 libstdc++)引起的。 首先,我从 macports 安装了 boost,然后使用 homebrew 安装并按照本教程进行操作(并使用 ./b2 和 g++-5 编译了 boost):

http://qiita.com/misho/items/0c0b3ca25bb8f62aa681#install-boost-for-gnu-compilers

没用。

我在 Properties/C/C++ Build 中的设置:

    Linker
    Command: /usr/local/bin/g++-5
    All Options: -L/Users/sam/boost_1_60_0/stage/lib -std=c++0x -I -O0 -g3 -Wall -c -fmessage-length=0
    Libs: /Users/sam/boost_1_60_0/stage/lib

    Compiler
    Command: /usr/local/bin/g++-5
    All Options: -std=c++0x -I/Users/sam/boost_1_60_0 -O0 -g3 -Wall -c -fmessage-length=0
    Includes: /Users/sam/boost_1_60_0


    lib$ otool -L libboost_locale.dylib
    libboost_locale.dylib:
    libboost_locale.dylib (compatibility version 0.0.0, current version 0.0.0)
    libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/local/opt/gcc/lib/gcc/5/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.21.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1225.1.1)
    /usr/local/lib/gcc/5/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

知道我的 boost 安装有什么问题吗?

【问题讨论】:

    标签: c++ eclipse macos boost


    【解决方案1】:

    现在可以了。刚刚在 Properties/C++ Build/MacOs X C++ Linker 的命令行模式中添加了选项 -lboost_locale:

        ${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -std=c++11 -lboost_locale
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-09
      • 2012-03-09
      • 1970-01-01
      • 2015-10-02
      • 2010-12-23
      • 2010-12-04
      • 1970-01-01
      相关资源
      最近更新 更多