【问题标题】:Unable to Compile program using Boost and Eureqa in C++无法在 C++ 中使用 Boost 和 Eureqa 编译程序
【发布时间】:2015-05-21 20:07:47
【问题描述】:

所以我将在 Xcode 中尝试一个简单的 Eureqa API 示例,如下所示: https://code.google.com/p/eureqa-api/

但是,当我尝试编译它时,此行中 boost 标头的 access.hpp 中似乎存在错误: ...

{
    // note: if you get a compile time error here with a
    // message something like:
    // cannot convert parameter 1 from <file type 1> to <file type 2 &>
    // a likely possible cause is that the class T contains a 
    // serialize function - but that serialize function isn't 
    // a template and corresponds to a file type different than
    // the class Archive.  To resolve this, don't include an
    // archive type other than that for which the serialization
    // function is defined!!!
    t.serialize(ar, file_version);
}

... 带有消息:'std::_1::pair'中没有名为'serialize'的成员

我应该怎么做才能解决这个问题?

【问题讨论】:

  • 谢谢!我试过了,然后在utility.hpp中弹出这个错误:ar &amp; boost::serialization::make_nvp("first", const_cast&lt;typef &amp;&gt;(p.first)); ar &amp; boost::serialization::make_nvp("second", p.second);说:命名空间'boost::serialization'中没有名为'make_nvp'的成员
  • 啊哈。我看到你确实回应了。正如您发现的那样,您需要对您回复的答案发表评论。或者/另外,您可以使用@JusufAurumMerukh 样式显式寻址(仅当它增加价值时)

标签: c++ serialization boost


【解决方案1】:

看起来你只是想包含标题

#include <boost/serialization/utility.hpp>

它定义了std::pair&lt;&gt; 的序列化。

编辑 发表评论后(回到家),我用 boost 1.58 在 linux 上重现了这个问题。事实上,编辑eureqa/implementation/connection_impl.h 以包含

#include <boost/serialization/utility.hpp>
#include <boost/serialization/nvp.hpp>

修复它:

g++ basic_client.cpp \
    -I/home/sehe/custom/boost/ \
    -I../../ \
    -c -o basic_client.o
g++ basic_client.o \
    /home/sehe/custom/boost/stage/lib/libboost_system.a \
    /home/sehe/custom/boost/stage/lib/libboost_serialization.a \
    /home/sehe/custom/boost/stage/lib/libboost_date_time.a \
    /home/sehe/custom/boost/stage/lib/libboost_thread.a \
    -lpthread  \
    -o basic_client

::_1 可能是使用内联命名空间进行版本控制的库实现 (libc++) 的产物。

【讨论】:

  • 谢谢!我试过了,然后在utility.hpp中弹出这个错误:ar &amp; boost::serialization::make_nvp("first", const_cast&lt;typef &amp;&gt;(p.first)); ar &amp; boost::serialization::make_nvp("second", p.second);说:命名空间'boost::serialization'中没有名为'make_nvp'的成员
  • @JusufAurumMerukh 我复制并测试了修复程序。我很确定您将包含插入到错误的位置。查看更新的答案
  • 好的,我明白了。我使用了我的mac xcode,之后弹出了很多这种类型的错误:Undefined symbols for architecture x86_64:我也不太明白你写的g++代码。
  • 这只是正在显示的 makefile 命令。我不写它们。我只在examples/basic_client 目录中做了make,就像文档告诉我的那样。这也将解决您的链接器错误,因为您未能链接必要的库...
猜你喜欢
  • 2012-02-27
  • 2012-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多