-
On the File menu, select New, and then select Project. The New Project dialog box appears.
-
In the Project Types pane, select the Visual C++ Projects node, and then in the Templates pane, select Win32 Project.
-
In the Name box, enter PGODemo.
-
Click the OK button. The Win32 Application Wizard appears.
-
Keep all default settings. Click the Finish button.
Now you have a solution and a project named PGODemo. Next, create a DLL project.
-
In the Solution Explorer, right-click on the solution, and select Add. And then click New Project. The New Project dialog box appears.
-
In the Project Types pane, select the Visual C++ Projects node, and then in the Templates pane, select Win32 Project.
-
In the Name box, enter PGODemoDLL.
-
Click the OK button. The Win32 Application Wizard appears.
-
In the Application Settings page, choose DLL Application type and click Finish.
You will now have a DLL project named PGODemoDLL. Next, add dependency on PGODemoDLL to PGODemo
-
On the Solution Explorer, double click on PGODemoDLL project, double click on PGODemoDLL.cpp and add the following code:
__declspec(dllexport) void HelloMessage(void)
{
MessageBox(NULL, "hello", "PGODemoDLL", MB_OK);
} -
On the Solution Explorer, double click on PGODemo project, double click on PGODemo.cpp and add the following declaration before the definition of the function _tWinMain:
__declspec(dllimport) void HelloMessage(void);
-
In –tWinMain before the main message loop add the following code:
-
In the Solution Explorer, right click on the PDODemo solution and click Project Dependencies. The Project Dependencies dialog will appear.
-
In the Dependencies page click chose PGODemo in the Projects combo box. Check the PGODemoDLL in the Depends on list.
Next, you will create the PGIRelease and PGORelease configurations.
-
In the Solution Explorer, right click on the solution, click Configuration Manager. Click on the Configuration combo box for PGODemo project and click <New …>. The New Project Configuration dialog box will appear.
In the Project Configuration Name edit box type PGIRelease and choose Release in the Copy Settings From combo box. Make sure the Also create new solution configuration check box is checked.
Repeat the same step on the PGODemoDLL project and to add the PGIRelease configuration to this project. Make sure that Also create new solution configuration check box is not checked this time.
-
Repeat step 16 for both projects to create PGORelease configuration. Make sure it also copies the settings from the Release configuration. Close the Configuration Manager dialog box.
Now we created two configurations, PGIRelease and PGORelease.
-
In the Solution Explorer, right click on the PGODemo Project and click Properties. In the Configuration combo box choose the PGIRelease configuration. In Configuration properties click General. Click the Whole Program Optimization combo box and choose the Profile Guided Optimization – Instrument option. Click Apply to save your changes.
-
In the Configuration combo box choose the PGORelease configuration. In Configuration properties click General. Click the Whole Program Optimization combo box and choose the Profile Guided Optimization - Optimize. Click Apply to save your changes.
-
Repeat steps 18 and 19 on the PGIRelease and PGORelease configurations for the PGODemoDLL project.
Now we will change the Intermediate Directory for the PGORelease configuration to be the same as the Output directory for the PGIRelease configuration for both projects.
-
In the Solution Explorer, right-click on the PGODemo Project and click Properties. In the configuration combo box choose the PGORelease configuration. In Configuration properties click General. In the Intermediate Directory, type PGIRelease. Click Apply and close the dialog.
-
Repeat step 21 for the PGODemoDLL project.
Next, we will add the path of PGODemoDLL.dll to the path environment variable of the PGODemo application.
-
In the Solution Explorer, right click on the PGODemo Project and click Properties. In the configuration combo box choose the PGIRelease configuration. In Configuration properties click Debugging. In the Environment, type the following and then click Apply:
path=%path%;$(SolutionDir)PGODemoDLL\PGIRelease
In the configuration combo box choose the PGORelease configuration. In Configuration properties click Debugging. In the Environment, type the following:
path=%path%;$(SolutionDir)PGODemoDLL\PGORelease
Then click Apply and then click OK to close the dialog.
-
In the Solution Explorer, right click on the PGODemo Project and click Properties. In the Configuration combo box choose the PGORelease configuration. In Configuration properties click Linker and then click Optimization. In the Profile Guided Database edit box, replace $(TargetDir) with $(IntDir).
Repeat this step for PGODemoDLL project.
-
In the Solution Explorer, right click on the PGODemoDLL Project and click Properties. In the configuration combo box choose the PGORelease configuration. In Configuration properties click Linker and then click Advanced. In the Import Library edit box, replace $(OutDir) with $(IntDir).
-
In the standard toolbar click the Solution Configurations combo and choose the PGIRelease configuration. In the Solution Explorer, right click on the solution and click Build Solution.
This will build the instrumented bits for both projects.
-
Click the Debug menu and click Start or Start without Debugging. This will start PGODemo. After you shutdown the application, two .PGC files will be created, one on each of the two otput folders PGODemo\PGIRelease and PGODemoDLL\PGIRelease.
-
In the standard toolbar click the Solution Configurations combo and choose the PGORelease configuration. In the Solution Explorer, right click on the solution and click Build Solution.
Now you have the PGO optimized images in the PGORelease configuration folders for both projects