Pavel Pavel - 1 year ago 73
C++ Question

Is it possible to have visual studio check whether or not the project will compile with g++?

Since C++ uses headers for now, sometimes one header includes another and you fail to notice it, as a result of that the code may compile with one compiler and not with the other, or maybe one feature is implemented in one compiler but not the other, so, I was wondering if there's a way to have visual studio check if the project will compile with both VS compiler and g++ somehow? Or do I just have to manually recompile with both compilers every time? If I have to recompile with both compilers, how can I automate that process with visual studio so I don't have to do it manually?

Answer Source

The development cycle of gcc is faster than that of MS Visual Studio. So asking Visual Studio "will my code be compiled correctly by g++?" is meaningless - it will never know which features and bugfixes the latest version of gcc has.

Also, there is no point in asking such a question at all - if you want to know "what will happen if I do X", just do X!

What you really want to know, I guess, is something like "Are my #include directives compatible with C++ Standard?". MS Visual Studio is just an implementation - it's not a portability-checking tool. It does its best to compile the code, and do it correctly, which is a great task by itself (with c++ being so hard to compile).

gcc is yet another implementation of c++, with its own headers. Actually, from my experience, the mingw c++ headers are more "minimalistic", that is, they try to not include one-another when possible. My guess is, they try to minimize compilation time for systems that don't use precompiled headers, while MS Visual Studio regards precompiled headers as an essential feature.

So better use gcc/mingw as your "standard compliance" check.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download