How to manage C ++ third-party libraries in Visual Studio

Source: Internet
Author: User

Currently, the project depends on many third-party libraries. It takes a long time to compile and install various third-party libraries each time a new environment is required, and various problems may occur, therefore, we decided to compile all the third-party libraries and put them into the sub-directories of the project, so we don't need to recompile them later.

Directory structure

The directory structure is as follows:

Some settings

After the directory structure is modified, some settings of the VS project need to be modified:

Output file path

In project Properties, Configuration Properties> General> Output Directory specifies the path where compiled lib, dll, and exe files are stored.

Some macros are used because the platform and Debug/Release versions are required:

$ (SolutionDir) indicates the directory where solution is located. src is used here.

$ (Platform) is the current compilation Platform, win32/x64

$ (Configuration) is the current compiled version, Debug/Release

Modify the include Directory of the header file and library file

You just need to modify it accordingly. Using the $ (Platform) $ (Configuration) macros can make the Configuration of each Platform/version the same without separate Configuration.

For details about which macros can be used, click "Macro>" in any edit window to view all macros.

Directory of the specified dll

The last one is important because no third-party libraries are installed, so how to find these dll when running the program is a problem.

The sequence for finding the dll during the execution of the exe is as follows. Theoretically, adding the dll to any stage can be:

Application Directory;

System Directory. The directory returned by GetSystemDirectory, usually the system disk WindowsSystem32;

16-bit system directory. This item is only for forward-compatible processing and can be ignored;

Windows directory. The directory returned by GetWindowsDirectory is usually the system disk Windows;

Current Directory. Directory returned by GetCurrentDirectory;

All directories in the environment variable PATH.

We have done so many things before to run the VS project in the new environment without any configuration, therefore, it is not the best way to manually copy files or modify environment variables.

Refer to this article.

In project Properties, Configuration Properties> Debugging> Environment can be used to add Environment variables to run programs in VS, which is only valid for the current project. We just need to add the paths of all third-party libraries. Be sure to use the relative paths. Otherwise, it will not work for another machine. There is a potential danger. If you have installed this third-party library in your system and added it to any of the above six links, it may cause some errors.

In addition, if you create a build, you need to write another script to package the required third-party dll and the compiled program.

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.