Standard C/C++ on Windows

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jdgdf566/article/details/78218266

概述

如果只需要比较经典的支持,选择MinGW而非MinGW-w64是可以的。MinGW-w64官方在线安装版很大大约半个G,有Python等。还有一个东西是TDM-GCC,貌似也不小貌似包含Fortran。
32位Linux下的GCC,默认是编译为32位代码。
64位Linux下的GCC,默认是编译为64位代码。
Window系统下的MinGW,总是编译为32位代码。因为MinGW只支持32位代码。
Window系统下的MinGW-w64(例如安装了TDM-GCC,选择MinGW-w64),默认是编译为64位代码,包括在32位的Windows系统下。
MinGW分为较早开发的MinGW32和之后为编译64位程序开发的MinGW-w64,MinGW32只能编译32位的程序,而mingw64不仅能编译64位程序,也能编译32位程序,还能进行交叉编译,即在32位主机上编译64位程序,在64位主机上编译32位程序。
生成目标:
32位版:加上 -m32 参数,生成32位的bin。
64位版:加上 -m64 参数,生成64位的bin。
debug版:加上 -g 参数,生成调试信息。
release版:加上 -static 参数,进行静态链接,使程序不再依赖动态库。加上 -O3 参数,进行最快速度优化。加上-DNDEBUG参数,定义NDEBUG宏,屏蔽断言。

MinGW-w64 threads: POSIX or Win32

估计是因为多线程是多个流水线互相关联所以无法“翻译”,才有了这个问题。
https://stackoverflow.com/questions/17242516/mingw-w64-threads-posix-vs-win32

  GCC comes with a compiler runtime library (libgcc) which it uses for (among other things) providing a low-level OS abstraction for multithreading related functionality in the languages it supports. The most relevant example is libstdc++'s C++11 <thread><mutex>, and <future>, which do not have a complete implementation when GCC is built with its internal Win32 threading model. MinGW-w64 provides a winpthreads (a pthreads implementation on top of the Win32 multithreading API) which GCC can then link in to enable all the fancy features.

I must stress this option does not forbid you to write any code you want (it has absolutely NO influence on what API you can call in your code). It only reflects what GCC's runtime libraries (libgcc/libstdc++/...) use for their functionality. The caveat quoted by @James has nothing to do with GCC's internal threading model, but rather with Microsoft's CRT implementation.

To summarize:

  • posix: enable C++11/C11 multithreading features. Makes libgcc depend on libwinpthreads, so that even if you don't directly call pthreads API, you'll be distributing the winpthreads DLL. There's nothing wrong with distributing one more DLL with your application.
  • win32: No C++11 multithreading features.

Neither have influence on any user code calling Win32 APIs or pthreads APIs. You can always use both.

  As MinGW uses the standard Microsoft C runtime library which comes with Windows, you should be careful and use the correct function to generate a new thread. In particular, the CreateThread function will not setup the stack correctly for the C runtime library. You should use _beginthreadex instead, which is (almost) completely compatible with CreateThread.
  Parts of the GCC runtime (the exception handling, in particular) are dependent on the threading model being used. So, if you're using the version of the runtime that was built with POSIX threads, but decide to create threads in your own code with the Win32 APIs, you're likely to have problems at some point.
Even if you're using the Win32 threading version of the runtime you probably shouldn't be calling the Win32 APIs directly.


文中的C++11/C11指的是Standard C++ 2011/C 2011
如果使用Win32 API的多线程函数,可能不利于GCC排错调试。所以对于复杂的多线程程序,与线程直接有关的部分可以先用POSIX thread写,再改为Win32的。

"Posix 启用 C + + 11 <thread>,<mutex>和 <future>"

NetBeans

NetBeans IDE 6.9.1的更新http://developer.51cto.com/art/201008/217321.htm

猜你喜欢

转载自blog.csdn.net/jdgdf566/article/details/78218266