为什么需要使用特定版本的 Visual C++ 构建 3ds Max 插件?
3ds Max SDK 中列出的要求规定,3ds Max 2011 的插件必须使用 Visual C++ 9.0 (Visual Studio 2008) 构建。
如果我使用不同版本的 Visual C++ 创建 DLL,二进制文件不会相同吗?这只是选择正确的编译器设置的问题吗?
如果我尝试使用 Visual C++ 2010 (Visual Studio 2010) 构建插件,会遇到哪些问题?
The requirements listed in the 3ds Max SDK state that plug-ins for 3ds Max 2011 must be built with Visual C++ 9.0 (Visual Studio 2008).
If I create a DLL with a different version of Visual C++, won't the binary be identical? Is this simply a matter of choosing the right compiler settings?
What problems will I run into if I try to build a plug-in using Visual C++ 2010 (Visual Studio 2010)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道具体是针对 3ds Max 的,但通常的原因是 C 运行时库。如果主机应用程序使用 CRT 的 DLL 版本,则插件也需要使用相同的版本。
否则,想象一下这样的情况:您的插件使用
malloc()
创建一些内存,并将其传递给主机应用程序,主机应用程序使用它,然后调用free()
。如果您的插件和主机应用程序使用不同的 CRT,则主机对 free() 的调用将会失败或崩溃,因为malloc()
并不是主机的 CRT 该内存块。I don't know specifically for 3ds Max, but the usual reason is the C Runtime library. If the host application uses the DLL version of the CRT, then plugins will also need to use the same version.
Otherwise, imagine the case where your plugin creates some memory using
malloc()
, and passes it to the host application, which uses it and then callsfree()
. If your plugin and the host application are using different CRTs, the host's call to free() will fail or crash because it wasn't the host's CRT thatmalloc()
ed that block of memory.二进制文件不会相同,但二进制接口应该相同,这正是您所需要的。
你不能使用VS2010的原因是它还没有达到生产质量。他们认为您至少应该等待 VS2010 SP1。
你认为他们只是固执和固执,是吗?毁了你所有的乐趣。他们有理由。好的。
由于这样的错误:
https://connect.microsoft.com/VisualStudio/feedback/details /565959
The binary won't be identical but the binary interfaces should be, which is what you need.
The reason you can't use VS2010 is because it is not yet production quality. They think you should wait for VS2010 SP1 at a minimum.
You think they are just being obstinate and stubborn, eh? Ruining all your fun. They have reasons. Good ones.
Because of bugs like this:
https://connect.microsoft.com/VisualStudio/feedback/details/565959
我使用 Visual Studio 2008 和 2010 进行插件开发。
我看到的唯一区别是用户需要 2010\2008 的 vs c++ 运行时版本。
但可能会有陷阱——但我还没有遇到任何问题。
I use both visual studio 2008 and 2010 for plugin development.
Only difference I've seen is that the user need the vs c++ runtime version for 2010\2008.
But there might be pitfalls - but I have not encountered any problems with it yet.
C++ 没有标准化的二进制接口。编译器“破坏”每个符号名称(即每个函数或静态数据)以包括有关命名空间和签名的信息,以便命名空间、参数重载等。可以工作。每个编译器都可以自由决定如何执行此操作。不同的 MSVS 编译器版本以不同的方式进行名称修改,因此通常您不能将使用 2005 编译的 C++ 库和使用 2008 编译的库链接在一起:这包括从 2005 可执行文件加载 2008 DLL(例如)。如果库之间的接口是 C,则可以这样做,只要相关函数用
extern "C"
标记以防止名称修改即可。在实践中,差异并不总是那么大:例如,我在使用 VS2005 SP1 编译 3ds Max 9 的库时从未遇到过麻烦,据说这需要不带服务包的 VS2005。微软正在尝试修复这种不兼容性,因此在VS2010中他们引入了一个选项,因此VS2010可以生成与VS2005程序或VS2008程序兼容的二进制文件(也许还有一些早期版本,我忘记了)。如果您必须创建一个插件来使用多个 3ds Max 版本,并且您不会遇到任何 VS2010 错误,那么这可能是一个不错的选择。此外,英特尔 C++ 编译器有一种模式,可以生成与您选择的 MSVS 版本兼容的二进制文件,如果它用于业余爱好或者您可以承受稍贵的价格标签,这可能是您更好的选择。 (他们通过复制 MSVS 进行名称修改的方式来实现这一点。)
C++ doesn't have a standardised binary interface. The compiler "mangles" each symbol name (i.e. each function or static data) to include information about namespaces and signature, so that namespaces, argument overloading, &c. can work. Each compiler is free to decide how to do this. Different MSVS compiler versions do name mangling in different ways, so in general you can't link a C++ library compiled with 2005 and a library compiled with 2008 together: this includes loading a 2008 DLL from a 2005 executable (for example). You can do this if the interface between the libraries is C, as long as the relevant functions are marked with
extern "C"
to prevent name mangling. And in practice the differences are not always that great: for example, I never had trouble using VS2005 SP1 to compile a library for 3ds Max 9, which supposedly requires VS2005 with no service pack.Microsoft is trying to fix this incompatibility, so in VS2010 they introduced an option, so VS2010 can produce binaries compatible with VS2005 programs or VS2008 programs (maybe some earlier versions too, I forget). If you have to create a plugin to work with multiple 3ds Max versions, and you don't get caught out by any VS2010 bugs, this is probably a good option. Also, the Intel C++ compiler has a mode where it produces binaries that are compatible with an MSVS version of your choice, which might be a better option for you if it's for hobby use or you can afford the slightly expensive price tag. (They achieve this by copying the way MSVS does name mangling.)