Chapter 2 Preparation -- 2.14.code: blocks configuration -- Global PATH variable

Source: Internet
Author: User
Tags wxwidgets
[Back To Directory] vernacular C ++

2.14. Code: blocks configuration -- Global PATH variable

In this chapter, we have installed many extension libraries. Next, we will write some code to call these libraries in the program, then, the compiler compiles the code, and finally the linker links the library with the program in some form. The compiler and the linker both need to "know" where to find these libraries.

"Library" is actually some files that are stored in a folder. Taking SDL as an example, we only need to provide such an absolute path: "E:/cpp_ex_libs/SDL/SDL-1.2.13/lib/SDL. DLL, then the linker will certainly not complain to us that "XXXX library cannot be found ".

When "absolute path" is used to specify the location of an extension library, there are some problems:

  • It is difficult for teams to work together during development. The reason is that different developers may install the same library in different directories. For example, if I installed cpp_ex_libs on an e-disk, I wrote an example project for you to download online. But after the download, I opened it with code: blocks. Because the project configuration content is in, all are "E:/cpp_ex_libs /......", If your "cpp_ex_libs" is on disk F, you have to find and replace them one by one! Alas, we have met this before.
  • Even for personal development, it is not convenient to use absolute paths. Take wxWidgets as an example. At first, I used version 2.8.7 to develop a software program. Later, wxWidgets was officially upgraded. I want to try the new version without deleting the old version, so install the new version in another directory. to upgrade the project, if the "absolute path" was originally written, I am afraid I have to modify the path information one by one.

 

Code: blocks uses the concept of "global variables" to solve this problem, that is, a specific string such as "$ {# wx}" is used to represent the installation path of wxWidgets. On my machine, I configured it to represent a location like "E:/cpp_ex_libs/wxWidgets/wxWidgets-2.8.9", on your machine, you can configure it to "F: /cppexlib/wx/wxWidgets-2.8.9 ". The Convention between us is to use "WX" as the name to represent the actual installation location of the wxWidgets extension library on their respective machines.

How can we solve the problem similar to different versions of the same extension library? Code: blocks provides a set of global variables, allowing multiple sets of global variables. For example, when I write an example program in this book, all the extended libraries use the latest version, but when developing for the company, the extended libraries of the earlier version are used. In this case, I can define two sets of variable sets, which can be switched between the two sets at work and at home (assuming that I work with the same PC at home ).

2.14.1. Create a global variable set: d2school

To facilitate teaching, we will create a variable set named d2school in code: blocks. Follow these steps.

Step 1:Run code: blocks; select "Settings> global variables" in the main menu. In the displayed dialog box "global variable Editor", click "new" in the first line, for example:

Figure 25 create a global variable set

Step 2:After completing the first step, a dialog box will pop up again. Enter "d2school" (without quotation marks) to exit.

Figure 26 new Set Name: d2school

2.14.2. global variable WX

We have a new set of global variables. Next we will create the first global variable: WX for this set.

Step 1:In the "Edit global variables" dialog box, click "new" in the second line to bring up a dialog box titled "new variables". This time, enter "WX" (excluding quotation marks ), confirm to exit.

Figure 27 create a global variable WX

Step 2:Then, in the "base" column on the left side of the "global variable editing" dialog box, enter the installation path of the wxWidgets extension library on your machine. For this book:

"E:/cpp_ex_libs/wxWidgets/wxWidgets-2.8.9" (without quotation marks, the same below)

You can find the actual installation path by clicking the "..." button on the right of the editing box.

In the "include" column, enter:

"E:/cpp_ex_libs/wxWidgets/wxWidgets-2.8.9/include"

In the "lib" column, enter:

& Quot; E:/cpp_ex_libs/wxWidgets/wxWidgets-2.8.9/lib & quot"

Effect

Figure 28 base, include, and Lib fields of the Wx variable

Step 3:To ensure that the information is correct, click the three "..." buttons to check the information.

2.14.3. Other global variables

  • Boost
Name Boost
Base E:/cpp_ex_libs/Boost/boost_1_36_0
Include E:/cpp_ex_libs/Boost/boost_1_36_0/include/boost-1_36
Lib E:/cpp_ex_libs/Boost/boost_1_36_0/lib
  • Iconv
Name Iconv
Base E:/cpp_ex_libs/iconv
Include E:/cpp_ex_libs/iconv/include
Lib E:/cpp_ex_libs/iconv/lib
  • Iconvpp
Name Iconvpp
Base E:/cpp_ex_libs/iconvpp
Include E:/cpp_ex_libs/iconvpp/include
Lib E:/cpp_ex_libs/iconvpp/lib
  • MySQL
Name MySQL
Base E:/cpp_ex_libs/MySQL
Include E:/cpp_ex_libs/MySQL/include
Lib E:/cpp_ex_libs/MySQL/lib
  • Mysqlpp
Name Mysqlpp
Base E:/cpp_ex_libs/MySQL ++/3.0.6
Include E:/cpp_ex_libs/MySQL ++/3.0.6/include
Lib E:/cpp_ex_libs/MySQL ++/3.0.6/lib
  • Xerces
Name Xerces
Base E:/cpp_ex_libs/xerces-C/xerces-c-src_2_8_0
Include E:/cpp_ex_libs/xerces-C/xerces-c-src_2_8_0/include
Lib E:/cpp_ex_libs/xerces-C/xerces-c-src_2_8_0/lib
  • Deelx
Name Deelx
Base E:/cpp_ex_libs/deelx
Include E:/cpp_ex_libs/deelx/include
Lib (Null)
  • SDL
Name SDL
Base E:/cpp_ex_libs/SDL/SDL-1.2.13.
Include

E:/cpp_ex_libs/SDL/SDL-1.2.13/include/SDL

(Note: unlike other include statements, the SDL sub-directory is used instead of the include statement)

Lib

E:/cpp_ex_libs/SDL/SDL-1.2.13/lib

(Previously, we copied SDL. DLL to this directory)

Vernacular C ++ [back to the Directory]

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.