C ++使用较新编译器的功能来生成供较旧编译器使用的代码(C++ Using features of a newer compiler to generate code for use by an o

编程入门 行业动态 更新时间:2024-10-27 15:27:01
C ++使用较新编译器的功能来生成供较旧编译器使用的代码(C++ Using features of a newer compiler to generate code for use by an older compiler)

我一直在研究“新”C ++标准(C ++ 11和C ++ 14)的一些特性,这让我想到了一些东西。 我目前正在为我的项目使用VC ++ 2008编译器(出于各种原因),这意味着我可以访问的最新标准是C ++ 03和TR1。 TR1有一些很好的东西,但是C ++ 11和C ++ 14中有很多功能可以使用。

我的问题是:是否有任何方法可以使用更新的编译器(比如MSVC2012或2013)来构建一些代码,以使用更新的C ++ 11和C ++ 14功能来构建库或DLL,然后将其链接到我的运行'08编译器的项目?

我能想到的唯一办法就是无法在我的'08编译器项目包含的头文件中获得C ++ 11或C ++ 14功能。 然而,只要所有“新”都隐藏在我的界面后面,这不应该工作吗?

I've been looking into some of the features of the "newer" C++ standards (C++11 and C++14), and that got me thinking about something. I'm currently using the VC++2008 compiler for my projects (for various reasons), which means that the newest standard I have access to is C++03, plus TR1. TR1 has some nice things in it, but there are features in C++11 and C++14 that would be nice to have.

My question is this: Would there be any way that I could build some code using a newer compiler (say MSVC2012 or 2013) to build libraries or DLLs using the newer C++11 and C++14 functionality and then link that into my project that's running the '08 compiler?

The only thing that I could think of that wouldn't work would be anywhere I had to have a C++11 or C++14 feature in a header included by my '08 compiler project. However as long as everything "new" were hidden behind my interface, shouldn't this work?

最满意答案

是的,但它会变得丑陋..因为ABI不兼容,你将不得不下降到“ extern "C" {} ”ABIness。

这意味着你无法传递C ++对象......就像我说的那样,很痛苦。 这也意味着它必须是DLL,因为你无法将静态库链接到另一个ABI。

它取决于你是否值得在C API中封装一个DLL来使用一些新特性,我建议你只是升级整个项目。

我几乎忘了,你可能无法链接导入库,所以你必须有一些使用LoadLibrary , GetProcAddress和FreeLibrary代码(我提到这是丑陋/痛苦?)。

Yes but its going to get ugly.. since the ABI is not compatible you'll have to go down to the "extern "C" {}" ABIness.

That means you can't pass C++ objects at all.. like I said, painful. It also means it must be a DLL since you won't be able to link in a static lib with another ABI.

Its up to you if its worth wrapping up a DLL in a C API just to use a couple of new features or not, I would recommend just upgraded the whole project though.

I almost forgot, you probably can't link the import lib either, so you'll have to have some code that uses LoadLibrary, GetProcAddress and FreeLibrary (did I mention this is ugly/painful?).

更多推荐

本文发布于:2023-07-25 22:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267147.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   代码   功能   较旧   features

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!