Quickly determine if code is Visual C++ or not - visual-studio

Is there a quick way to determine whether a Visual Studio C++ project is written in plain C++ or Visual C++?

If any files include the lines #pragma once or #include "stdafx.h", it's very likely Visual C++.
(Are there any other compilers that implement #pragma once?)

No -- Visual C++ will compile most plain C++ without any problems. If you want to check for use of Windows-specific "stuff", checking for inclusion (directly or indirectly) of <windows.h> would probably be a reasonable start.

If is Visual C++ it usually has a project.sln or project.vcproj file in the project directory.

Related

How to remove windows.h calls from application?

I have an application that uses windows.h but I am tasked with removing the calls to Windows functions.
I am using Visual Studio Express 2010 and when I delete the #include "windows.h" line the code is still able to compile and I can right click and "Go To Definition" for all the variables associate with the windows include file.
I removed $(WindowsSdkDir)include; from the VC++ Directories in the Configuration Properties page but that didn't seem to make a difference. I believed that could be the case because windows.h can be found at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\windows.h on my computer.
How do I completely break this link so Visual Studio can give me errors for all calls to that library?
Use the /showIncludes command switch to search for indirect includes of windows.h
http://msdn.microsoft.com/en-us/library/hdkef6tk.aspx

Library importing: #pragma comment VS Visual studio project input

using #pragma comment(lib, "../../xxx.lib")
using Visual studio project option
What is the advantage and disadvantage between two method?
I'm finding way which is better convenient to manage for many projects.
And what method does Microsoft recommend?
The advantage of #pragma comment is that the user of your library cannot forget to add the setting. Or add the wrong one, it is not uncommon to get lost at the difference between the debug and release build and the /MD vs /MT build. One disadvantage is that troubleshooting linker problems can be difficult in some cases.
There's a third way that's hard to beat for convenience in a solution. Right-click the project that requires the library and click Project Dependencies. Tick the library project. This ensures that the library project is always built before the project and the .lib is automatically added.

gcc compiled code on visual studio

Assume I have source code for a lib/tool that works on gcc compiler. Can I use the same code and compile it in visual studio. will that be possible at all? If it is possible, how do I do it?
if you are just using all the standard C/C++ library like stdio.h, stdlib.h, etc. it should work fine. Pure console program should work fine. If you used some GUI related library (especially if you are porting over from unix to window) then it might not work.
To do so, you can simply just create a new project in visual studio and add the existing source code into the project workspace. Compile it, if you encounter any error, just post here or try solve if you know how
It depends on your code, GCC support a variant of C (C99) which Visual Studio doesn't support yet.
If your trying to compile a Unix program on Windows you best bet will be to use Cygwin.
Check this question for pointers on using Cygwin in Visual Studio.

Include QT file problem in Visual Studio 2008

When I type
#include <QObject>
it complains that it couldn't find file.
but if I type
#include <QtCore\QObject>
It works properly.
I moved VS2005 to VS2008, this was not the case in VS2005, and it started with VS2008. Why am I getting this error?
Actually it's not so big problem. You need to check you include directories and add (path_to_qt_headers)/QtCore, (path_to_qt_headers)/QtGui and directories for other modules you are using. According to your problem description you have added only (path_to_qt_headers) itself.
If Qt set up correctly both #include <QObject> and #include <QtCore/QObject> should work but second one works in more cases. I remember I saw some notice somewhere in the Qt documentation that it might be better to using second include style. At the same time this long include version is recommended in the KDE coding guidelines.
For myself I preffere to follow #include <QtModule/QClass> include convention
Maybe installing the Visual Studio addin for Qt would solve the problem (besides providing advanced debug and Qt project management tools).

Multi-Target Visual Studio Project: one source code

Any suggestions on how one could go about setting up a build system that would compile one or two libraries against a couple of different platforms/targets.
The main project is in Visual Studio.
For example, I have a library:
nav.lib
It compiles on Windows and Linux with a few tweaks.
The executable that uses the library, win_nav.lib, only compiles on Windows at the moment with OpenGL.
I'm porting this code to the iPhone. Although I know I can't compile and link the entire library on windows I would like to try to compile the graphics code with OpenGL includes and OpenGLES includes. (Perhaps I can test out my opengles code on the windows machine as well?)
I plan to change my graphics file to include based on preprocessor flags:
#ifdef USE_OPEN_GL_FULL
#include <opengl/gl.h>
#else
#include <opengles/gl.h>
#endif
So, how would you go about doing this?
Using a couple of different scripts or different projects in Visual Studio?
This is what "Solution Configurations" are for. By default Visual Studio creates Release and Debug configurations, but you can add your own custom configurations too. The Project options are different for each configuration, so just set your #define in the configuration that needs it.
When you are running your automated build you just set the /build parameter to the name of the configuration you want to compile with.
Within VS you can use the Configuration Manager to target different builds and use different libraries within your code.

Resources