[C + +] managing C + + third-party libraries in Visual Studio engineering

Source: Internet
Author: User

The current project relies on many third-party libraries, each time a new environment to compile/run, it takes a long time to compile/install a variety of third-party libraries, and there will be a variety of problems, so decided to compile all the third-party libraries, into the project subdirectory, and then do not have to repeat the compilation.

Directory structure

The organized directory structure is as follows:

Some settings

After modifying the directory structure, some of the settings for the VS project need to be modified to illustrate:

Path to output file

In the project properties, Configuration properties > General > Output Directory Specify the path to the compiled Lib/dll/exe store.

Because of the need to sub-platform, debug/release version, so the use of some macros:

    • $ (SolutionDir) indicates the directory where solution is located, here is SRC
    • $ (Platform) is the currently compiled platform, Win32/x64
    • $ (Configuration) is the currently compiled version, debug/release
Modify the Include directory for header and library files

Modify it accordingly, using the two macros (Platform) $ (configuration), you can make the configuration of each platform/version identical and do not need to be configured separately.

Specifically want to know what you can use the macro, you can any of the edit window, click the "macro>>" button, expand all macro view.

Specify the directory where the DLL resides

This last one is important because now all third-party libraries are not installed, so how to find these DLLs when running the program is a problem.

EXE in the run time to find the DLL sequence as follows, in theory to add the DLL to any link can be:

    1. The directory where the application resides;
    2. System directory. GetSystemDirectory returns the directory, usually the system disk \Windows\System32;
    3. 16-bit system directory. The item is only for forward-compatible processing and can not be considered;
    4. Windows directory. GetWindowsDirectory returns the directory, usually the system disk \ windows;
    5. The current directory. GetCurrentDirectory the returned directory;
    6. Environment variables all directories in path.

We've done so many things before, in order to run the VS project in a new environment without having to do any configuration, so any manual copy/modify environment variable is not the best way to do it.

Refer to this article http://my.oschina.net/u/243648/blog/62847, because our DLLs are scattered in many folders, the last method is to add these directories to the environment variable path, of course, not manually added, Instead, it is added to the VS configuration.

In the project properties, Configuration properties > Debugging > Environment can add some environment variables to be added to run the program in VS, only valid for the current project. We put the path of all third-party libraries into the line, pay attention to must use relative path, otherwise change a machine or not to use. There is a potential danger that if you have this third-party library installed in your system and added to any of the 6 links above, you may cause some errors.

In addition, if the build, you will need to write another script, the need to use the third-party DLL and compiled programs together to package, so it is OK.

[C + +] managing C + + third-party libraries in Visual Studio engineering

Related Article

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.