Thursday, October 7, 2021

Case Study 1: VC ++ project configurations in Visual Studio

VC ++ project configurations in Visual Studio. use these two projects to set up project parameters.

My note on these special parameters.

  1. Case Study 1: Eat Your Own Dogfood
  2. Source code organization suggestion How to use symbolic links for an easier code reuse between different projects

    study this project and understand these project property settings:

    C/C++ =>General, Optimization, Code Generation, Language, Precompiled Headers, Output Files, Advanced, all these sections have very good settings and configurations.

    they are good examples to utilize .

    Cool_A:

    Configuration Properties =>General=>
    Output Directory:$(SolutionDir)lib\$(PlatformTarget)\$(Configuration)\
    Intermediate Directory: $(SolutionDir)o\$(ProjectName)\$(PlatformTarget)\$(Configuration)\
    Configuration Type: static library(/lib)
    Target Name: $(ProjectName)

    C/C++ =>General =>
    Additional Include Directories: $(SolutionDir)include

    Librian=>General=>
    output File: $(OutDir)$(TargetName)$(TargetExt)
    Incremental Link Database File: $(IntDir)$(TargetName).ilk


    Cool_B:

    Configuration Properties =>General=>
    Output Directory:$(SolutionDir)lib\$(PlatformTarget)\$(Configuration)\
    Intermediate Directory: $(SolutionDir)o\$(ProjectName)\$(PlatformTarget)\$(Configuration)\
    Configuration Type: static library(/lib)
    Target Name: $(ProjectName)

    Configuration Properties =>Advanced =>
    Build Log File:$(IntDir)$(MSBuildProjectName).log

    C/C++ =>General =>
    Additional Include Directories: $(SolutionDir)include

    C/C++ =>Precompiled Headers =>
    Precompiled Header: Use(/Yu)
    Precompiled Header File: stdafx.h
    Precompiled Hader Output File: $(InDir)$(TargetName).pch

    C/C++ =>Output Files =>
    Program Database File Name: $(OutDir)$(TargetName).pdb
    All other option: $(IntDir)
    Program Database File Name: $(OutDir)$(TargetName).pdb
    Program Database File Name: $(IntDir)vc$(PlatformToolsetVersion).pdb

    Linker=>General=>
    output File: $(OutDir)$(TargetName)$(TargetExt)
    output File(example:): .\Debug\SplashWndDemo.exe
    Incremental Link Database File: $(IntDir)$(TargetName).ilk
    Linker=>Manifest File=>
    Generate Manifest: Yes(/Manifest)
    Manifest File: $(IntDir)$(TargetName)$(TargetExt).intermediate.manifest
    Allow Isolation: YES
    Enable USer Account Conttrol (UAC): Yes(/MAIFESTUAC)
    UAC Execution Level: asInvoker(/level='asInvoker")
    UAC Bypass UI Protection: No(iuAccess="false")
    Linker=>Debugging=>
    Generate Debug Info: Generate DEbug Information(/DEBUG)
    Generate Program Database File: $(OutDir)$(TargetNAme).pdb


    SupperApp:

    Configuration Properties =>General=>
    Output Directory: $(SolutionDir)app\$(PlatformTarget)\$(Configuration)\
    Intermediate Directory: $(SolutionDir)o\$(ProjectName)\$(PlatformTarget)\$(Configuration)\
    Configuration Type: application(.exe)
    Target Name: $(ProjectName)
    Configuration Properties =>Advanced =>
    Build Log File:$(IntDir)$(MSBuildProjectName).log
    Build Log File(standard):$(IntDir)$(MSBuildProjectName).log

    C/C++ =>General =>
    Additional Include Directories: $(SolutionDir)include

    C/C++ =>Precompiled Headers =>
    Precompiled Header: Use(/Yu)
    Precompiled Header File: stdafx.h
    Precompiled Hader Output File: $(InDir)$(TargetName).pch

    C/C++ =>Output Files =>
    All other option: $(IntDir)
    Program Database File Name: $(IntDir)vc$(PlatformToolsetVersion).pdb
    Program Database File Name(standard): $(OutDir)$(TargetName).pdb

    Linker=>General=>
    output File: $(OutDir)$(TargetName)$(TargetExt)
    output File(example:): .\Debug\SplashWndDemo.exe
    Incremental Link Database File: $(IntDir)$(TargetName).ilk
    Additional Include Directories:$(SolutionDir)lib\$(PlatformTarget)\$(Configuration)\

    Linker=>Manifest File=>
    Generate Manifest: Yes(/Manifest)
    Manifest File: $(IntDir)$(TargetName)$(TargetExt).intermediate.manifest
    Allow Isolation: YES
    Enable USer Account Conttrol (UAC): Yes(/MAIFESTUAC)
    UAC Execution Level: asInvoker(/level='asInvoker")
    UAC Bypass UI Protection: No(iuAccess="false")
    Linker=>Debugging=>
    Generate Debug Info: Generate DEbug Information(/DEBUG)
    Generate Program Database File: $(OutDir)$(TargetNAme).pdb

  3. Case Study 2: 2-D Interpolation Functions
  4. Various algorithms for 2D interpolation. I will study its project configurations:

    Interp2:

    Configuration Properties =>General=>
    Output Directory(standard): $(SolutionDir)app\$(PlatformShortName)\$(Configuration)\
    Output Directory(standard): $(SolutionDir)$(Configuration)
    Intermediate Directory: $(SolutionDir)o\$(PlatformShortName)\$(Configuration)\
    Intermediate Directory(standard): $(Configuration)
    Configuration Type: static library(/lib)
    Target Name: $(ProjectName)
    Configuration Properties =>Advanced =>
    Build Log File:$(IntDir)$(MSBuildProjectName).log
    Build Log File(standard):$(IntDir)$(MSBuildProjectName).log

    C/C++ =>General =>
    Additional Include Directories: $(SolutionDir)include

    C/C++ =>Precompiled Headers =>
    Precompiled Header: Use(/Yu)
    Precompiled Header File: stdafx.h
    Precompiled Hader Output File: $(InDir)$(TargetName).pch

    C/C++ =>Output Files =>
    All other option: $(IntDir)
    Program Database File Name: $(IntDir)vc$(PlatformToolsetVersion).pdb
    Program Database File Name(standard): $(OutDir)$(TargetName).pdb

    Linker=>General=>
    output File: $(OutDir)$(TargetName)$(TargetExt)
    output File(example:): .\Debug\SplashWndDemo.exe
    Incremental Link Database File: $(IntDir)$(TargetName).ilk
    Additional Include Directories:$(SolutionDir)lib\$(PlatformTarget)\$(Configuration)\

    Linker=>Manifest File=>
    Generate Manifest: Yes(/Manifest)
    Manifest File: $(IntDir)$(TargetName)$(TargetExt).intermediate.manifest
    Allow Isolation: YES
    Enable USer Account Conttrol (UAC): Yes(/MAIFESTUAC)
    UAC Execution Level: asInvoker(/level='asInvoker")
    UAC Bypass UI Protection: No(iuAccess="false")
    Linker=>Debugging=>
    Generate Debug Info: Generate DEbug Information(/DEBUG)
    Generate Program Database File: $(OutDir)$(TargetNAme).pdb


  5. Case Study 3: DWinLib Build Process
  6. Overview of build process for DWinLib programs with or without using libraries. I will review these project configurations:

    MY SUMMARY:

    CheckPoint 1: Create all required project folders and copy all files from zipped project file, and then add existing files(including header files) into this project from solution view in Visual Studio 2019.

    CheckPoint 2: Configure precompiled header settings in property view: set additional include directories for these header files location.

    CheckPoint 3: Set Linker=>System->Subsystem: Windows.

    CheckPoint 4: Resolve TCHAR issues: set conformance mode to 'NO', or include <tchar.h >

    CheckPoint 1:

    Build From Scratch

    Step 0: create a new folder on drive D: D:\Programs\MyProgs\AwesomeProg

    Step 0.5: create a new folder on drive D: D:\Programs\LibsAndUtils\DWinLib. copy all files & folders under unzipped folder D:\Programs\DWinLibExamples6.04\D\Programs\LibsAndUtils\DWinLib to this new folder DWinLib for new project use. also use "adding existing files" to DWinLib filter as demonstrated in step 3 and repeated in Step 4.

    Step 1: copy all of the files from "D:\Programs\MyProgs\DWinLibExamples\MdiDwlDockWork" (WITHOUT THE "VS_FILES" SUBDIRECTORY) to the new "AwesomeProg" directory.

    Step 2: Open Visual Studio and create a new completely empty C++ project. Place it at "D:\Programs\MyProgs\AwesomeProg", and give it the name "AwesomeProg". Check the box to place the solution and project in the same directory, and make sure the dropdown item of "Create new solution" is selected. Press the 'Create' button.

    Step 3: for this example, just delete the "Header Files" filter, rename the "Resource Files" filter to "DWinLib", and leave the "Source Files" filter as-is.

    Step 4: create this folder: "D:\Programs\LibsAndUtils\DWinLib. copy all source files(no folder) from unzipped project folder LibsAndUtils\DWinLib. need to add these files into DWinLib filter in the project.

    Step 5: Then, in Windows Explorer, drag all of the files (and NONE of the subdirectories) from "D:\Programs\MyProgs\AwesomeProg" onto the "Source Files" in the new project:

    My Note 1: To fix that, right-click on the "AwesomeProg" project in the Solution Explorer, select "Properties" from the bottom of the menu, and then navigate to Configuration Properties -> C/C++ -> Precompiled Headers and change the "Precompiled Header" line to "Use (/Yu)", and change the file name from "stdafx.h" to "PrecompiledHeaders.h" on the "Precompiled Header File" line. Make certain "All Configurations" is selected in the upper-left Configuration dropdown and press "OK".

    Afterwards, right-click on the "PrecompiledHeaders.cpp" file in the Solution Explorer and select "Create (/Yc)" on the "Precompiled Header" line.

    My Note 2 This is because even though Visual Studio knows where the files we added to it are placed, it needs us to explicity specify those locations for its compilation and linking steps. So right-click on the "AwesomeProg" project in the Solution Explorer, select "Properties" at the bottom, and maneuver to the Configuration Properties -> C/C++ -> General location. Make certain "All Configurations" is selected in the top left dropdown, and then add the DWinLib directory and the program directory to the "Additional Include Directories" line. Assuming your setup is the same as mine, they are:

    Press "OK", and then try re-running the program again. You will get a bunch of errors. After compilation is finished (if you wait that long), the top 'Red X' in the error list will be:
    "Error C2440 'initializing': cannot convert from 'const wchar_t [17]' to 'TCHAR *'".

    Fix: When DWinLib was initially created, it used Windows 'TCHAR' macro to allow easy use of UNICODE or Multi-Byte Character Sets. That, combined with stricter default Visual Studio settings, results in this error which isn't really an error. To get around it, go back to Configuration Properties -> C/C++ -> Language and change "Conformance mode" to "No."

    Rebuild, and Visual Studio will spit out an error:
    "'clientWindowC': undeclared identifier".

    Fix: For this error, we simply need to tell DWinLib that we are building an MDI application. To do so, go to Configuration Properties -> C/C++ -> Preprocessor and add "DWL_MDI_APP" to the "Preprocessor Definitions".

    When the solution is rebuilt again, you will receive a new error:
    "LNK2019 unresolved external symbol _main..."

    Fix: When we created the Visual Studio project as a blank C++ project, it defaulted to a console application. To change this, the fix is in :Configuration Properties -> C/C++ -> Linker -> System , where the SubSystem needs to be changed to Windows. With that in place, the program will finally appear when the Local Windows Debug button is pressed.

    Building a DWinLib Program Using DWinLib's Library

    Step 1: let us recreate the MdiDwlPwcStudio project. So make a directory at "D:\Programs\MyProgs\DwlPwcStudio". Copy the files from "D:\Programs\MyProgs\DWinLibExamples\MdiDwlPwcStudio" into it, excluding the subdirectory it contains.

    Step 2: Then create a new blank C++ project in Visual Studio at "D:\Programs\MyProgs\DwlPwcStudio",with the name "DwlPwcStudio",

    Step 3: drag the files from the new DwlPwcStudio folder into the Solution Explorer "Source Files" filter. (You can delete the other filters if you want.). it means: add these files into this new empty project.

    Step 4: separately Build this library in two version:

    1. "D:\Programs\LibsAndUtils\DWinLibLibrary\MDI_Unicode\Debug"
    2. "D:\Programs\LibsAndUtils\DWinLibLibrary\MDI_Unicode\Release"

    Step 5: Once they are built, come back to this project. We are in the Configuration Properties -> Linker -> General page,

    1. and in the upper-left corner change the dropdown to 'Debug'. Add "D:\Programs\LibsAndUtils\DWinLibLibrary\MDI_Unicode\Debug" to the "Additional Library Directories". Press 'Apply,'
    2. then change to 'Release' and add "D:\Programs\LibsAndUtils\DWinLibLibrary\MDI_Unicode\Release" to it. Press "Apply" again, and switch back to "All Configurations" in the Configuration dropdown.
    3. You must also add the name of the library to the Configuration Properties -> Linker -> Input -> Additional Dependencies line. That library is "DWL_MDI_Unicode.lib". Release and Debug versions have the same name, so you don't have to mess with independent settings.

    Step 6.Change the Configuration Properties -> C/C++ -> Precompiled Headers to 'Use', the Precompiled Header file to "PrecompiledHeaders.h", and make the "PrecompiledHeaders.cpp" file into the one that gets compiled by closing the configuration box and opening up the configuration box for that file itself by right-clicking on it in the Solution Explorer.

    Step 7. Go back to the project configuration pages instead of the PrecompiledHeader.cpp file configuration. Add the necessary items to Configuration Properties -> C/C++ -> General -> Additional Include Directories. The DWinLib one remains the same, the program path changes, though:

    1. D:\Programs\LibsAndUtils\DWinLib
    2. D:\Programs\MyProgs\DwlPwcStudio

    Step 8. Change Configuration Properties -> C/C++ -> Language -> Conformance mode to "No."

    Step 9. Configuration Properties -> Linker -> SubSystem needs to be changed to Windows.

    Step 10. Add "DWL_MDI_APP" to Configuration Properties -> C/C++ -> Preprocessor

    Step 11.At this point, Visual Studio is not very bright. We need to change to "Debug" and remove "_CONSOLE;" from the preprocessor definitions, and we also need to repeat this for the "Release" option.

    Step 12. The reason for this is DWinLib uses a macro definition for docker addition compilation. So add "DWL_USE_DOCKERS" to the Configuration Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions for All Configurations. Recompile and everything works correctly!

    My Tips: we need to check macro defined in Library project and set them up in the client projects.

    when I build this project in Release mode I got this error message:

    Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in DwlPwcStudio.obj
    1. LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in file.obj
    2. I am Integrating Matlab, C and Cuda together in a project. I used Matlab mix in order to connect matlab mx function written in c with the cuda runtime library, a linking error appear about conflict in static release and dynamic release between the c file and the library. Can anyone solve this?

    3. mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease'
    4. I try to compile a project on Windows with Qtcreator and Cuda library. The compilation works fine on a simple cuda file and cpp files but when I try to add more than one cuda file I get that error:

    5. /MD, /MT, /LD (Use Run-Time Library)
    6. Indicates whether a multithreaded module is a DLL and specifies retail or debug versions of the run-time library..

  7. Reference:: DWinLib 6: Pretty WinAPI Incorporation
  8. My DWinLib Windows API wrapper combined with Francisco Campos's Pretty WinAPI framework.

  9. Pretty WinAPI Class
  10. New library version that is not WTL/MFC dependent

    A user's message is very useful:Pandele Florin

  11. DWinLib - The Guts
  12. A little about how things work behind the scenes in DWinLib! In this article, you will get an overview of the internal workings of DWinLib, a semi-simple wrapper for the Windows API..

    Macros and other Basics

  13. Set compiler and build properties
  14. In the IDE, all information that is needed to build a project is exposed as properties. This information includes the application name, extension (such as DLL, LIB, EXE), compiler options, linker options, debugger settings, custom build steps, and many other things. Typically, you use property pages to view and modify these properties. To access the property pages, choose Project > projectname Properties from the main menu, or right-click on the project node in Solution Explorer and choose Properties..

  15. Information needed about the C++ Preprocessor->Preprocessor Definitions _CONSOLE vs _LIB
  16. We have an (unmanaged) static library (Configuration Type: Static Library; Use of MFC: Shared DLL; Runtime Library: Multithreaded DLL) that I discovered has the "C++ Preprocessor->Preprocessor Definitions" as "WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)" (Release configuration).

    It has been this way for some time - I can hazard a guess as to how, but is irrelevant to what I need to know for this post. This library is implicitly linked in hundreds of programs. Based on a new static library I created it, the "C++ Preprocessor->Preprocessor Definitions" was "_LIB", not "_CONSOLE".

    I have been unable to find any detailed information on what "_LIB" and "_CONSOLE" do or how it affects the library/exe.

    Can you provide me with the info as to what these macros do?

    I believe that it should be switched from "_CONSOLE" to "_LIB", but what sort of issues could crop up (being that it has been this way for a long time)?

    You probably want this to align with the subsystem you're using. Linker/System/SubSystem can be /SUBSYSTEM:WINDOWS which aligns with preprocessor _WINDOWS and _LIB, /SUBSYSTEM:CONSOLE aligns with _CONSOLE. This largely has to do with how the application entry point is determined, but just for the record, the preprocessor definitions don't do anything, you'd define them for convenience so that you can use the _LIB, _CONSOLE, _WINDOWS, _UNICODE, etc. in your compiler macros for logic purposes..

  17. Predefined macros
  18. The Microsoft C/C++ compiler (MSVC) predefines certain preprocessor macros, depending on the language (C or C++), the compilation target, and the chosen compiler options.

    MSVC supports the predefined preprocessor macros required by the ANSI/ISO C99, C11, and C17 standards, and the ISO C++14 and C++17 standards. The implementation also supports several more Microsoft-specific preprocessor macros. Some macros are defined only for specific build environments or compiler options. Except where noted, the macros are defined throughout a translation unit as if they were specified as /D compiler option arguments. When defined, the macros are expanded to the specified values by the preprocessor before compilation. The predefined macros take no arguments and can't be redefined...

  19. 4.2 Macro Descriptions and Use
  20. This section describes the preprocessor macros associated with Rogue Wave products (Table 2), followed by a series of tables that show which build types each macro applies to. Use Table 2 to determine which macros you may need to defined based on the Rogue Wave libraries you are linking to, and the rest of the tables to determine whether those macros are needed by the build configuration you are using...

  21. Is there a #define associated with the SubSystem
  22. I'm creating main with a macro and need to be able to check the selected SubSystem at compile time, /SUBSYSTEM:WINDOWS or /SUBSYSTEM:CONSOLE, in order to generate the appropriate main function. Is there a #define I can check that accomplishes this?

  23. Visual C++ Quick Start and IDE Reference
  24. The purpose of this document is to help someone who is encountering Visual C++ for the first time to get started quickly with writing C++ programs using the programming environment provided by the latest Visual Studio IDE (Integrated Development Environment)..

  25. MODULE 10 THE C/C++ PREPROCESSOR DIRECTIVES 1
  26. The C/C++ preprocessor directives programming skills that should be acquired:

    1. Able to understand and use #include.
    2. Able to understand and use #define.
    3. Able to understand and usemacros and inline functions.
    4. Able to understand and use the conditional compilation – #if,#endif,#ifdef,#else, #ifndef and #undef..
  27. MODULE 10THE C/C++ PREPROCESSOR DIRECTIVES 2: #define etc.
  28. The C/C++ preprocessor directives programming skills that should be acquired:

    1. Able to understand and use #error,#pragma,# and ## operators and #line.
    2. Able to display error messages during conditional compilation.
    3. Able to understand and use assertions..

No comments:

Post a Comment