【问题标题】:Making .so from .cpp: Undefined symbols for architecture x86_64: Boost.Python MacPorts GCC6 not Clang从.cpp制作.so:架构x86_64的未定义符号:Boost.Python MacPorts GCC6 not Clang
【发布时间】:2016-12-02 01:08:58
【问题描述】:

我正在尝试在 Boost.org 上关注 Boost.Python 的 Exposing Classes tutorial。我已经成功地完成了first tutorial,并且在注释掉代码时,一旦出现类就会出现错误。一切都崩溃的部分是从 .cpp 文件制作 .so 文件。我得到了明显的常见:'架构 x86_64 的未定义符号:'。我已经检查了关于这个主题的多个问题,并且基本上都与我的案例无关。我在 OSX 10.11.6 上,我使用 macports 来安装 boost 和 gcc6。我已经设置好了所有东西,所以我实际上使用 gcc 和 g++ 而不是 clang。这就是为什么我不相信我的问题是related to this one,因为我使用的是实际的 g++,如果我的理解正确,我不应该处理这个 libstc++ 和 libc++ 问题。我所有来自 macports 的包,以及 macports 本身都是最新的。有人愿意分享一些见解吗?

当我运行创建 .so 的命令时:(我相信我一定是缺少一些指向 Boost 中库的链接,但我不知道它是什么)

g++ -shared -o hello.so -fPIC hello.cpp `python-config --cflags --libs` -lboost_python

我收到一点警告和简短的错误消息,但是 hello.so.dSYM 文件已创建并保存在目录中:

cc1plus:警告:命令行选项“-Wstrict-prototypes”对 C/ObjC 有效,但对 C++ 无效

架构 x86_64 的未定义符号:“boost::python::objects::function_object(boost::python::objects::py_function const&, std::pair const&)”,引用自:

    init_module_hello()     in cchDzx8t.o

“boost::python::objects::register_dynamic_id_aux(boost::python::type_info, std::pair ()(void))”,引用自:

    init_module_hello()     in cchDzx8t.o

ld:未找到架构 x86_64 的符号

collect2: 错误:ld 返回 1 个退出状态

我的 .cpp 代码与该教程中显示的完全相同:

#include <boost/python.hpp>
using namespace boost::python;
struct World {   
    void set(std::string msg) { this->msg = msg; }
         std::string greet() { return msg; }
         std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
    class_<World>("World")
    .def("greet", &World::greet)
    .def("set", &World::set)
    ;   
}

【问题讨论】:

    标签: gcc g++ macports boost-python .so


    【解决方案1】:

    无论您是否正确安装了 GCC/G++,MacPorts 总是在默认使用 libc++ 编译的系统上针对 libc++ 构建其 C++ 软件。

    这意味着您的 MacPorts 版本的 Boost 是使用 libc++ 编译的,这意味着您不能将它与 GCC/G++ 一起使用(除非您跳过一些额外的障碍来将 libc++ 与 GCC 一起使用)。

    尽管您猜测您的问题不是您在链接的其他帖子中描述的问题,但确实如此。您的选择是:

    • 使用 clang++
    • 使用 g++ 构建您自己的 Boost 副本

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-08
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 2014-08-07
      • 2012-07-20
      • 1970-01-01
      • 2015-08-23
      相关资源
      最近更新 更多