简体   繁体   English

Microsoft Visual C ++是否与Windows平台绑定?

[英]Is Microsoft Visual C++ tied to windows platform?

I want to learn C++ and I want to know if using Microsoft VC++ will tie me to Windows. 我想学习C ++,并且想知道是否使用Microsoft VC ++可以使我与Windows绑定。 I specially need my project to also run on Mac. 我特别需要我的项目也可以在Mac上运行。 My projects are all Class libraries and have no dependency to UI. 我的项目都是类库,并且不依赖于UI。 They are just calculations or file/network IO. 它们只是计算或文件/网络IO。

I really like working in Visual Studio and Microsoft way overall. 我真的很喜欢整体上在Visual Studio和Microsoft中工作。 So my priority is to go VC++ unless it makes painful to build cross platform apps for Windows and Mac. 因此,我的首要任务是使用VC ++,除非为Windows和Mac构建跨平台应用程序很麻烦。 I mean at the compiler, libraries and language level. 我的意思是在编译器,库和语言级别。 I don't want my parallel app to fall apart on certain platforms. 我不希望我的并行应用程序在某些平台上崩溃。

I personnaly use Visual Studio to build my code on Windows and other compilers to build the same code on other platforms (Mac, Linux, Android...). 我个人使用Visual Studio在Windows上构建我的代码,并使用其他编译器在其他平台(Mac,Linux,Android ...)上构建相同的代码。

To be sure you don't get locked with Windows, make sure (at least, it's not exhaustive): 为确保您不会被Windows锁定,请确保(至少,它并不详尽):

  • You don't use any win32 API (prefer cross plateforme libraries like boost for instance for network, file system access...) 您不使用任何win32 API(更喜欢跨平台的库,例如boost用于网络,文件系统访问...)
  • You don't use 3rd party libraries only available for Windows 您不使用仅适用于Windows的第三方库
  • Don't use CString, or anyother Microsoft class. 不要使用CString或任何其他Microsoft类。 Prefer STL. 首选STL。
  • Be careful with file system case sensitiveness too! 也要注意文件系统的大小写敏感性! ( #include "Foo.h" while file is "foo.h" on disk will work on PC, not under Mac/Linux). (当磁盘上的文件为“ foo.h”时, #include "Foo.h"将在PC上运行,而不是在Mac / Linux下运行)。 Prefer naming ALL your files in lower case. 最好用小写字母命名所有文件。
  • ... ...

You may want to have a look at CMake . 您可能想看看CMake This tool can help you generating compilation project file for the same source to be compiled on different plateform. 该工具可以帮助您为要在不同平台上编译的同一源生成编译项目文件。 Then, you can generate vcproj/sln files to compile your code with Visual Studio on Windows, MakeFile(s) to compile it under Linux and XCode project files to compile it under MacOS. 然后,您可以生成vcproj / SLN文件与编译代码的Visual Studio在Windows上, 生成文件(一个或多个)进行编译的Linux下的XCode项目文件编译它在MacOS下。 If somewone wants to compile you code under Windows with another compiler than Microsoft, it's also possible! 如果有人想用Microsoft以外的其他编译器在Windows下编译您的代码,那也是可能的!

Also note that recent version of VS (2015) propose to compile for other targets that Windows (at least Android). 另请注意,VS(2015)的最新版本建议针对Windows(至少是Android)的其他目标进行编译。 But never tried that. 但是从来没有尝试过。

The compiler itself is pretty standard confroming by know (if you turn off the extensions) and more importantly, you can use the clang frontend (which is the default compiler on Mac) directly from within VS2015, so it is definitvely possible to write cross-platform code in VS (although it's certainly easier to use Windows specific constructs than it where if you'd use eg cygwin). 编译器本身是知道非常标准confroming(如果您关闭扩展),更重要的是,你可以直接在VS2015使用铛前端(这是在Mac上默认的编译器),所以它是definitvely 可以编写跨VS中的平台代码(尽管使用Windows特定的结构肯定比使用cygwin的情况要容易得多)。

However, the windows API for network I/O is different from the one for Mac, so you should probably use a corssplatform library like boost asio for that. 但是,用于网络I / O的Windows API与用于Mac的Windows API不同,因此您可能应该使用诸如boost asio之类的corssplatform库。

As far as multithreading is concerned, you can do it in a standard and portable manner using the standard library's functions, classes and synchronization primitives, but the past has shown that they are often not the most efficient way to go. 就多线程而言,您可以使用标准库的函数,类和同步原语,以标准且可移植的方式来实现,但是过去表明,它们通常不是最有效的方法。 However, in most situations you'll want to use a more highlevel library for parallel programming anyway. 但是,在大多数情况下,无论如何,您都将希望使用更高级的库进行并行编程。 The default on Windows is the PPL which is - I believe - not cross-platform, but there are other libraries you can use Windows上的默认值是PPL,我相信-它不是跨平台的,但是您可以使用其他

Finally, you can use VS to remotely build your applications on Mac or Linux PCs using their local compilers and libraries. 最后,您可以使用VS使用本地编译器和库在Mac或Linux PC上远程构建应用程序。 However, I don'T know, how well that works in practice. 但是,我不知道在实践中效果如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM