Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run the MSVC preprocessor and compiler in two separate steps?

I'd like to run the Microsoft Visual Studio Compiler cl.exe without invoking the preprocessor. Is this possible? I thought that simply compiling preprocessed source code (using the /c flag) would make the preprocessor run being a no-op, but apparently that's not the case. I did a bit of benchmarking. Here's a little source file (main.cpp) which just includes some code:

#include <iostream>
#include <string>
#include <windows.h>

Here are some different compiler invocations and their timings:

1: cl /c main.cpp                             ~1.02s
2: cl /EP main.cpp > main-preprocessed.cpp    ~0.5s
3: cl /c main-preprocessed.cpp                ~0.75s

It seems that compiling preprocessed source code is already a bit faster (the preprocessor doesn't need to do anything). However, the difference between 1 and 2 suggests that the actual compiler and assembler just needs a bit more 0.5s. So compiling the preprocessed source code (as done in step 3) is a bit slower than I hoped.

Is there any way to just run the compiler and assembler, without invoking the preprocessor? I'm interested in solutions for MSVC6 up to MSVC10.

like image 272
Frerich Raabe Avatar asked Jan 21 '11 09:01

Frerich Raabe


People also ask

Can I use a different compiler in Visual Studio?

You can select the compiler and corresponding toolset that will be used to build a project with the “Platform Toolset” property under General Configuration Properties for C++ projects. Any installed compilers that are applicable to your project type will be listed in the “Platform Toolset” dropdown.

How do I change the compiler in Visual Studio?

In Visual Studio You can set compiler options for each project in its Visual Studio Property Pages dialog box. In the left pane, select Configuration Properties, C/C++ and then choose the compiler option category.

What is MSVC and GCC?

GCC is for people who don't mind spending 4 hours at the computer making it work properly. MSVC is for those who don't care about C and want it to install without any pokin' around.

How do I change the compiler path in VS code?

In the Windows search bar, type 'settings' to open your Windows Settings. Search for Edit environment variables for your account. Choose the Path variable in your User variables and then select Edit. Select New and add the Mingw-w64 destination folder path to the system path.


1 Answers

To my knowledge there is no way to run the compiler without the preprocessor (regardless of the fact that it doesn't do anything.

However seperating the 2 stages will obviously be slower as you are adding a write to file and then read back of that file. If it doesn't need to do those writes it can hold it in memory and you save a tonne of time waiting for the disk to be written to & read from.

ie Even if you could disable the pre-processor it would still be slower than running both stages simultaneously.

like image 121
Goz Avatar answered Oct 01 '22 20:10

Goz