Boost序列化:XCode 5项目中的链接器错误,从CMake生成(w /最小完整示例) [英] Boost Serialization : Linker errors in XCode 5 project, generated from CMake (w/ minimal complete example)

查看:312
本文介绍了Boost序列化:XCode 5项目中的链接器错误,从CMake生成(w /最小完整示例)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的主要项目中,构建管理被推迟到CMake。一切都对我们的不同的依赖,包括Boost :: System,但我们不能让它编译这个Boost ::序列化的最小示例。

In our main project, the build management is deferred to CMake. Everything was going fine for our different dependencies, including Boost::System, but we cannot get it to compile this minimal example for Boost::Serialization.

# Untested with previous versions, yet should work
cmake_minimum_required(VERSION 2.8.11)

project(SerialCmake)

# Boost dependency
set(BOOST_ROOT CACHE PATH "Path to Boost library")
find_package(Boost 1.55 COMPONENTS serialization system)

# Create the target
add_executable(${PROJECT_NAME} main.cpp)

include_directories(${Boost_INCLUDE_DIR})

target_link_libraries(${PROJECT_NAME}
    ${Boost_LIBRARIES})



CPP主档案


$ b b

CPP main file

#include <fstream>
#include <boost/archive/text_oarchive.hpp>

class Serializable
{
    friend class boost::serialization::access;

public:
    Serializable(int a): a(a)
    {}

private:
    template <class Archive>
    inline void serialize (Archive &ar, const unsigned int version)
    {
        ar & a;
    }

    int a;
};

int main(int argc, char **argv)
{
    Serializable s1(1);

    // Save
    {
        std::ofstream ofs(argv[1]);
        boost::archive::text_oarchive oa(ofs);
        oa << s1;
    }
    return 0;
}



更多信息



我们的版本:

Some more info

Our versions :


  • XCode 5.0.2

  • CMake 2.8-12

  • Boost 1.55

  • OSX 10.8

  • XCode 5.0.2
  • CMake 2.8-12
  • Boost 1.55
  • OSX 10.8

实际上找到了CMake中列出的两个Boost库(它们在CMake输出上被列出)。

The two Boost libraries listed in the CMake are actually found (They are listed on CMake output as such).

Boost已首次使用默认参数构建,第二次按照此帖中的说明。错误与两个构建相同。 (实际上,我认为两个版本都是好的,因为在非CMake项目中使用库,通过将它们添加到XCode,如同一篇文章中所述)。

Boost has been built first time with default parameters and a second time following the instructions in this post. The errors are the same with the two builds. (Actually, I think both builds are alright, since using the libraries in a non CMake project, by adding them to XCode as described in the same post, does work.)

我们得到了几个(未定义的符号)链接器错误:

We are getting several (undefined symbols) linker errors :


架构x86_64的未定义符号:

boost :: archive :: text_oarchive_impl :: save(std :: string
const&),引用自:
void boost :: archive :: save_access :: save_primitive(boost :: archive :: text_oarchive& std :: string const&)in
main.o

boost :: archive :: text_oarchive_impl :: text_oarchive_impl (std :: ostream&
unsigned int),引用自:main @ b:boost :: archive :: text_oarchive :: text_oarchive(std :: ostream&
boost :: archive :: basic_text_oprimitive ::〜basic_text_oprimitive(),
引用自:
boost :: archive :: text_oarchive_impl ::〜text_oarchive_impl()
在main .o ld:没有为架构x86_64找到符号

Undefined symbols for architecture x86_64:
"boost::archive::text_oarchive_impl::save(std::string const&)", referenced from: void boost::archive::save_access::save_primitive(boost::archive::text_oarchive&, std::string const&) in main.o
"boost::archive::text_oarchive_impl::text_oarchive_impl(std::ostream&, unsigned int)", referenced from: boost::archive::text_oarchive::text_oarchive(std::ostream&, unsigned int) in main.o
"boost::archive::basic_text_oprimitive::~basic_text_oprimitive()", referenced from: boost::archive::text_oarchive_impl::~text_oarchive_impl() in main.o ld: symbol(s) not found for architecture x86_64

任何方向?请参见,我们要求将应用程序与Boost :: Serialization和Boost :: System)链接。

Any direction ? (As you can see, we are asking to link the application against both Boost::Serialization and Boost::System).

推荐答案

检查所有库是否通过 find_package 命令实际找到。最简单的方法
要添加 REQUIRED 子选项:

You need to check that all libraries is actually found by find_package command. Easiest way to do it is to add REQUIRED sub-option:

find_package(Boost 1.55 REQUIRED system serialization)

适用于我。 Xcode 5.0.2,Boost 1.55,CMake 2.8.12.1,OS X 10.9。我使用自定义boost构建(不是系统)与静态库。

Works fine for me. Xcode 5.0.2, Boost 1.55, CMake 2.8.12.1, OS X 10.9. I'm using custom boost build (not system) with static libraries.

IMHO没有必要清除 BOOST_ROOT variable:

IMHO there is no need to clear BOOST_ROOT variable:

set(BOOST_ROOT CACHE PATH "Path to Boost library")

如果已经发现boost(由其他父项目),您将做两次查找工作,如果项目使用自定义提升位置,您将重写它。

If boost is already found (by other parent project) you will do find-work twice, if project use custom boost location, you will rewrite it.

这篇关于Boost序列化:XCode 5项目中的链接器错误,从CMake生成(w /最小完整示例)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆