我一直在研究“新”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?).
更多推荐
发布评论