【发布时间】:2014-11-21 22:38:09
【问题描述】:
我正在使用 C++CLI 在 Visual Studio 2012 中编写一个 Windows 窗体 GUI 应用程序,我确实需要使用 Boost 双向映射来协调一些 GUI 元素值与一些内部结构中的值。我下载并解压缩了 boost 包,然后在项目的属性菜单中,我将 Boost 位置添加到配置属性 -> VC++ 目录 -> 包含目录。
但是,当我添加 boost 包含时(仅此而已,甚至没有声明 boost::bimap 对象)
#include <boost/bimap.hpp>
我得到错误
error C3389: __declspec(dllexport) cannot be used with /clr:pure or /clr:safe
error C3395: 'boost::serialization::void_cast_register' : __declspec(dllexport) cannot be applied to a function with the __clrcall calling convention
当我遵循编译错误时,我最终出现在“void_cast_fwd.hpp”和下面包含“BOOST_DLLEXPORT”的行中,但我不确定如何处理它。
#ifndef BOOST_SERIALIZATION_VOID_CAST_FWD_HPP
#define BOOST_SERIALIZATION_VOID_CAST_FWD_HPP
// MS compatible compilers support #pragma once
#if defined(_MSC_VER)
# pragma once
#endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// void_cast_fwd.hpp: interface for run-time casting of void pointers.
// (C) Copyright 2005 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// gennadiy.rozental@tfn.com
// See http://www.boost.org for updates, documentation, and revision history.
#include <cstddef> // NULL
#include <boost/serialization/force_include.hpp>
namespace boost {
namespace serialization {
namespace void_cast_detail{
class void_caster;
} // namespace void_cast_detail
template<class Derived, class Base>
BOOST_DLLEXPORT
inline const void_cast_detail::void_caster & void_cast_register(
const Derived * dnull = NULL,
const Base * bnull = NULL
) BOOST_USED;
} // namespace serialization
} // namespace boost
#endif // BOOST_SERIALIZATION_VOID_CAST_HPP
我是 .NET 和 C++CLI 的新手,不知道如何更改编译器命令 /clr:pure 或 /clr:safe。
任何关于如何在我的应用程序中使用这个 boost 库的想法将不胜感激。
另外,我现在并不担心可移植性,我只关心它可以在 Windows 上编译。我假设我在 .NET 中使用 C++CLI 比尝试使用 boost 库更多的是可移植性限制,但我也有兴趣听取对此的意见。
谢谢!
【问题讨论】:
-
我不记得有困难。寻找隐藏
__declspec(dllexport)的定义(BOOST_LIB_* 或类似的)并确保它为您的项目正确定义。你不会暴露你的类型,所以不要导出它们。 -
@sehe 感谢您的快速回复。我对此有点陌生,你能详细说明如何找到隐藏
__declspec(dllexport)的定义吗? -
跟着编译器报错就好了。库包含
__declspec(dllexport)的机会可能接近于零(因为 Boost Serialization 是一个可移植库)。 -
@sehe 嗯,对不起,但我仍然很困惑。当我遵循编译器错误时,我最终得到了 void_cast_fwd.hpp,当您说“确保为您的项目正确定义它”时,我无法说出我需要做什么。我已经编辑了我的问题以将代码包含在这个 hpp 中。如果你能用“为你的项目正确定义”的意思解释一下,我真的很感激,因为我完全被困在这里了。