"Reprint" vs Configuration path and macros

Source: Internet
Author: User

Original path: http://blog.csdn.net/puttytree/article/details/7838419

Before introducing the project configuration, please explain two points

1.

In a project configuration, it is best not to use relative paths, not to use absolute paths

You should try to use a macro to specify all paths

See the path-related macros in VS2008 in the following places

A.c/c++-> General, additional include directories

B. Click on the button on the right to bring up a dialog box

C. Click the macro button in the bottom right corner to see all the macros

2.

In the case of project setup, if Debug and release have the same properties, then in the property page, the best configuration option is set to: all Configurations

This allows the debug and release sections to be modified at the same time.

The directory structure of our project is as follows:

In order to implement such a directory structure, the following configuration is required when building a project:

The first three items are the specified settings that must be modified, followed by a user-selectable

1. Configure the project's output directory and intermediate directory

Configuration properties, general-Output directory:

$ (SolutionDir) build\link\$ (ProjectName) \$ (ConfigurationName)

Configuration properties, general-and intermediate directories:

$ (SolutionDir) build\compile\$ (ProjectName) \$ (ConfigurationName)

2. Configure the directory where the output files are located

Output file, general--Link

$ (OutDir) \$ (ProjectName). dll

Links--general--Additional library directories:

$ (SolutionDir) lib\$ (ConfigurationName)

For other projects such as Vbcswitcher, if you also want to refer to the library in the current LIB, the additional library directory is:

$ (SolutionDir): \ebase\lib\$ (ConfigurationName)

3. Configure post-build events, copy the final output files from the output directory to the bin directory, and copy the output Lib files to the Lib directory

Build Event--post-build event--command line:

Copy $ (TargetPath) $ (solutiondir) bin\$ (ConfigurationName)

Copy $ (TargetDir) $ (TargetName). Lib $ (solutiondir) lib\$ (ConfigurationName)

Other projects such as Vbcswitcher, if you want to output to this directory, the post-build event can be written as:

Copy $ (TargetPath) $ (SolutionDir): \ebase\bin\$ (ConfigurationName)

Copy $ (TargetDir) $ (TargetName). Lib $ (SolutionDir): \ebase\lib\$ (ConfigurationName)

If there are controls that need to be registered, they can be fully registered in the post-build event

Echo regsvr32 $ (targetfilename) >> $ (SolutionDir) bin\$ (configurationname) \register.bat

Echo regsvr32/u $ (targetfilename) >> $ (SolutionDir) bin\$ (configurationname) \unregister.bat

4. If you want to specify debug commands and working directories, set the

Commands for debugging:

$ (SolutionDir) \bin\$ (configurationname) \$ (TargetFileName)

Working directory for debugging:

$ (SolutionDir) \bin\$ (configurationname) \

See the following section for details:
The instructions in the following sections are excerpt from:
Http://blog.csdn.net/rogeryi/archive/2007/01/13/1481923.aspx

Directory structure settings and management for the VC 2005 solution Roger ([email protected]A medium-sized solution typically contains multiple projects, some of which produce static libraries, some output dynamic libraries, some for unit testing, and some that produce final application execution files. In addition, some third-party libraries are used, depending on the needs of the project. Therefore, a reasonable directory structure for the solution, not only can make the code management more organized, project members are also easier to work with each other, more importantly, can make the final application of the installation package, source code packaging release and transfer becomes very easy. Solutions and projects: from VC6 the VC series uses solutions (solution) instead of the original workspace for organizing and managing multiple related projects (project). The article first demonstrates a virtual solution and the directory structure that we expect to get, and then uses the VC2005 Project Setup feature to achieve our needs step-after-step. Virtual Solutions:The virtual solution, named GMA, contains a dynamic link library project Chocolatemilk and an application project Puremilk, which requires a third-party library Log4cxx (Apache log4j C + + ported version for log output). Log4cxx is compiled in the form of a dynamic library, so we need 3 things for it, namely header files, import libraries (Log4cxx.lib, log4cxxd.lib), and dynamic link libraries (log4cxx.dll). Suppose we expect a directory structure such as: 1. GMA is the solution Catalog 2. Puremilk and Chocolatemilk are project directory 3. The Lib directory is used to store import libraries or static libraries (including third-party libraries and their own projects) 4. Incl? header file for storing third-party libraries 5. The bin directory holds all dynamic link libraries and execution files, including its own outputs and third-party libraries, distinguishing between release and debug two versions. In addition, the process requires external data files and configuration files needed at startup, etc. can be placed in the directory 6. Temp is used to hold temporary makefile, where compile holds the obj file generated at compiler compile time, and link stores the linker's output file. The above directory structure clear, one side knows, when our program needs to make the installation package or to package the source release, it can make our life easier ^_^ we only need to package all the files in the "/gma/bin/release/" directory when we make the installation package. When we publish and transfer the source code, we can package all the files and directories under "/gma/" except the temp directory (or bin if you do not need to execute the file). Our needs are clear, but VC 2005 does not automatically do for us all the above things. However, we do not need to write a complex compilation script (makefile), simply modify the project's default settings. What we need VC to do for US includes:1. Use "/gma/temp/compile/" as the intermediate Directory 2 used when compiling the project. Use "/gma/temp/link/" as the output directory for project links 3. When the project is an application, copy the execution file to "/gma/bin/release/" or "/gma/bin/debug/" at the end of the build, and when the project is a dynamic link library, in addition to copying the DLL to the Bin, copy the import library to "/gma/lib/" 4. When the project is an application, run the Execute file under "/gma/bin/debug/" or "/gma/bin/release/" while debugging, and use "/gma/bin/debug/" or "/gma/bin/release/" as the working directory First look at the macros that you can use in your project settings, which are commonly used:

ConfigurationName Configuration name, usually debug or release
IntDir Intermediate directory used by the compiler, output obj file
OutDir Output directory used by the linker
ProjectDir Project directory
ProjectName Project name
SolutionDir Solution Catalog
TargetDir directory where the destination output file resides
Targetext The extension of the target output
TargetFileName Target output file name, including extension
TargetName Target output name, not including extension
TargetPath Full path name of the destination output file

  to set up Chocolatemilk first: 1. Use "/gma/temp/compile/" as the intermediate Directory 2 used when compiling the project. Use "/gma/temp/link/" as the output directory of the project link     note the highlighted section, first change the configuration to all configuration, This allows us to simultaneously modify the debug and release parts,  output directory (output directory, linker) fields: $ (solutiondir) \temp\link\$ (ProjectName) \$ ( ConfigurationName)  intermediate directory (intermediate directory, compiler) field filled in: $ (solutiondir) \temp\compile\$ (ProjectName) \$ ( ConfigurationName)  3. Copy the dynamic link library to "/gma/bin/release/" or "/gma/bin/debug/" after the build is finished, copy the import library to "/gma/lib/"   we usually add the letter "D" after the Debug version of the output library. To indicate that this is the debug version, in Debug configuration, modify the Import library field:    VC allows us to set the script to execute before and after the build, so in order to complete 3 we need to write the script executed after the build:    Fill in command line, Debug config:  copy $ (TargetPath) $ (solutiondir) \bin\$ (configurationname) \;copy $ (TargetDir ) $ (TargetName) D.lib $ (SolutionDir) \lib\; release configuration:  copy $ (TargetPath) $ (solutiondir) \bin\$ ( ConfigurationName) \;copy $ (TargetDir) $ (TargetName). Lib $ (SolutionDir) \lib\;  is set separately because the VC does not represent the macro name of the import library-_-p  ok, that's it, you can compile the Chocolatemilk project. It's all right, but make sure the target directory of the copy is set up beforehand.   Next we set up the application project Puremilk:1. Use "/gma/temp/compile/" as the intermediate Directory 2 used when compiling the project. The output directory that uses "/gma/temp/link/" as the project link first changes the configuration to the all configuration, which allows us to simultaneously modify the debug and release parts; output directory, linker) field: $ (solutiondir) \temp\link\$ (ProjectName) \$ (configurationname) Intermediate directory (intermediate directory, compiler) field filled in: $ ( SolutionDir) \temp\compile\$ (ProjectName) \$ (ConfigurationName) 3. After the build is finished, copy the execution file to "/gma/bin/release/" or "/gma/bin/debug/" in command line, under all configuration: Copy $ (TargetPath) $ (solutiondir) \bin\$ ( ConfigurationName); 4. Run the execution file under "/gma/bin/debug/" or "/gma/bin/release/" while debugging, and fill in the Working Directory command field with "/gma/bin/debug/" or "/gma/bin/release/": $ ( SolutionDir) \bin\$ (configurationname) \$ (targetfilename) Working directory fields fill in: $ (solutiondir) \bin\$ ( ConfigurationName) \ So it's done, now you can compile the executable and debug it.

"Reprint" vs Configuration path and macros

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.