如何在.NET C ++ CLI GUI应用程序中使用Boost类 [英] How to use Boost classes in a .NET C++CLI GUI application

查看:103
本文介绍了如何在.NET C ++ CLI GUI应用程序中使用Boost类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++ CLI在Visual Studio 2012中编写Windows窗体GUI应用程序,我确实需要使用Boost双向映射来将某些GUI元素值与某些内部结构中的值进行协调.我下载并解压了boost软件包,然后在项目的Properties菜单中将Boost位置添加到Configuration Properties-> VC ++目录-> Include Directories.

I am writing a Windows Forms GUI application in Visual Studio 2012 using C++CLI and I really need to use the Boost bidirectional map to coordinate some GUI element values with values in some internal structs. I downloaded and unzipped the boost package and then in my project's Properties menu I added the Boost location to Configuration Properties -> VC++ Directories -> Include Directories.

但是,当我添加boost包含时(什么都没有,甚至没有声明boost :: bimap对象)

But, when I add the boost include (and nothing else, not even declaring a boost::bimap object)

#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"的行中,但是我不确定该如何处理.

When I follow the compile errors I end up in "void_cast_fwd.hpp" and on the line below that contains "BOOST_DLLEXPORT" but I'm not sure what to do with it.

#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.

I am new to .NET and C++CLI and not sure how to change the compiler commands /clr:pure or /clr:safe.

任何有关如何在应用程序中使用此Boost库的想法都将不胜感激.

Any thoughts on how I can use this boost library in my application would be greatly appreciated.

此外,我现在不担心可移植性,我所关心的只是它可以在Windows上编译.我假设我在.NET中使用C ++ CLI的事实要比尝试使用Boost库更多地是一种可移植性限制,但是我也很想听听对此的意见.

Also, I am NOT worried about portability right now, all I care is that it compiles on Windows. I am assuming the fact that I am using C++CLI in .NET is more of a portability restriction than trying to use boost libraries, but am interested to hear opinions on this too.

谢谢!

推荐答案

C ++/CLI编译器通常可以确定代码是本地代码还是托管代码.但并非总是如此,这具有产生您所看到的错误的技巧.您需要帮助并明确说明哪些声明是本机的.

The C++/CLI compiler can usually figure out whether code is native or managed. But not always, and that has a knack for generating the errors you see. You need to help and be explicit about what declarations are native.

首先,请确保正确设置了/clr选项,并且您尝试使用的Boost代码没有任何安全或纯粹的意义.项目+属性,常规,公共语言运行时支持设置.确保它是纯/clr.

First make sure you have the /clr option set correctly, there is nothing safe or pure about the boost code you are trying to use. Project + Properties, General, Common Language Runtime Support setting. Ensure it is plain /clr.

然后告诉编译器,boost标头包含带有#pragma的本机代码:

Then tell the compiler that the boost headers contain native code with a #pragma:

#pragma managed(push, off)
#include #include <boost/bimap.hpp>
#pragma managed(pop)

这应该解决编译错误.

这篇关于如何在.NET C ++ CLI GUI应用程序中使用Boost类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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