I have to compile one executable on Windows, the first time. I'm using visual studio 2003 and want the equivalent of a command line macro definition.
What's the VS equivalent of g++ -Dthismacro=1?
Update
For VS 2003, I found it this way. Right clicking on the project, I go to "Properties". From there, it's Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions
since you seem to be coming from a linux-flavor, why not use the commandline: the argument for macro definition is actually the same, except the compiler executable is cl and not g++:
cl -Dthismacro=1
although the documentation says the convention is to use /D, most (all?) arguments can be used with the - switch.
When using visual Studio, you can verify this: if you add a preprocessor symbol the way earlz suggested, this can be seen as /D"thismacro=1" option under Configuration->C/C++->Command Line
If you right click on the project, it should bring up a project configuration page. Goto "build" and then you should be able to define preprocessor symbols.. (hopefully it works the same in 2003 as 2008)
Related
I am creating a vcxproj project to build C code (UEFI) which builds with custom build steps. I need the source C and H files to display with full IntelliSense support, then when I hit F5, I want the project to build if any source file changed, then start Debug. If nothing changed, just start the Debugger. The Build just needs to run my command line commands, I do not need Visual Studio to use its C compiler and Linker. It seems the only way to build with custom steps is to set Configuration Type to either Makefile or Utility.
One problem with Makefile project is that it always builds the NMake command line even if I did not touch any files. Is there a way to configure build so that it only builds if any of the source files changed, like with Application or Dynamic Library project types?
Another problem (only with Makefile project) is that it forces IntelliSense to some C++ mode that marks all my CHAR16* L"Strings" as errors: a value type of const wchar_t* cannot be used to initialize an entry of type "CHAR16*". There are Additional Options under NMake IntelliSense menu, but no matter what I put there makes no difference. There is no documentation about what the available switches are and their effect. Is it possible to configure a Makefile project to C mode? BTW, VS2013 does not have this problem, it is only VS2019 and VS2022.
Utility project type does not have the above-mentioned problem with IntelliSense, but it always returns "build up-to-date" even when I change source files, which should set a dirty flag and cause a build. The build only starts when I select Rebuild. Is it possible to configure a Utility project to build when a source file changed?
I want to print all the warnings in my project built in VS2008. As has been suggested at other questions, the project properties only gives me up to /W4 level warnings when I want to enable /Wall. Below is a snapshot of properties. Is there a way to enable /Wall in VS2008 for a project?
I assume you are working with C++? In this case, you can add this flag in the "Command Line" options directly:
Notice that the output can be too verbose to be usable.
According to CUDA 5 and beyond and other sources I should be able to compile and link several separate .cu files through the -dc option. My only question is where exactly do I place this option in Visual Studio 2010. It probably is simple just can't figure it out :(
Okay after again a very good look it was simple :( Configuration -> CUDA C/C++ -> Command Line now you can add additional options below the printout of the command line parameters.
Is it possible that I can just compile all CPP files under a project and without linking etc. the project?
The only way I know to do this is by specify the /c switch when you compile the code. Unfortunately, this option is not available from within the Visual Studio development environment, so you'll need to build your code on the command line by calling cl.exe directly. To make things easy on yourself, use the Visual Studio Command Prompt to do so.
Not sure if it's possible to get MSBuild to do this, the documentation is unclear whether the limitation is Visual Studio itself or if it's a limitation of MSBuild. I haven't actually tried for myself.
Alternatively, you can build individual source files from within the IDE by pressing Ctrl+F7 (at least, assuming the default C++ development settings). If that fails, it's also available as the "Compile" option located in the "Build" menu.
I'm not sure whether this will do what you need, but may be worth a try: create a project for an executable (rather than a library) and include all cpp files in it. Add a main() function that just returns zero. Set the C++ optimisation option to 'optimise references' (/OPT:REF). This may just compile all the cpp files but effectively ignore them during the link stage since none of them are referenced by the application.
You don't say why you need to do this - is it because linking takes a huge amount of time?
I'm using Visual Studio 2008 on my main build system. I've been playing with Visual Studio 2010 on another one. It appears that the tool still only wants to use one core when compiling unless you specify the /MP switch in the compiler switches (see How do I turn on multi-CPU/Core C++ compiles in the Visual Studio IDE (2008)?). I have to do this for every project. Is there a way to make VS always do this?
Create environment variable "CL" and set it to "/MP". Microsofts compiler cl.exe always prepend command line flags with this variable.
Some compiler features and options like #import aren't compatible with /MP flag. You will need to add /MP1 to projects used #import in a code. This will disable /MP for those projects.
Your can create a property sheet that all of your projects include, and set the /MP flag in that property sheet.
In Visual Studio 2010, you could put it in the Microsoft.Cpp.Win32.user property sheet, which is included in new projects by default (it has the old Visual C++ directories and other default settings defined in it). I don't know that modifying the default property sheet is really a good idea, but it's certainly an option.