Use third-party library principles in VS (Configure SQLite database)

Source: Internet
Author: User
Tags sqlite sqlite database

When we write a program, we inevitably use a third-party library file, The source files (. cpp) are seldom used, most of which are the header files that are declared on the class and the libraries that encapsulate the classes (static lib or dynamic DLLs), such as the library of the iostream we write the program with, of course, this is the official library that has been set up, so we need to configure ourselves when we use a third party library

The Library of C + + places the declarations of functions and classes in *.h, and implements them in *.cpp or *.cc. After compiling, the *.CPP,*.CC,*.C is packaged into a. lib file, which protects the source code.

Therefore, to use a library, in addition to include his header file, but also in the link process to add lib.



There are two ways to solve this problem.

There are two main ways to do this:

The first : We can put the library file (. lib) We need, Already the header file (. h) Copy to our program directory, in fact, as long as the copy to the program directory can be, because the compiler will automatically in the project in the file in the document search, if we use the library file has a dynamic link file, we usually copy it to our program executable file exists in the file, so we can in our process Used in the sequence.

But there is a drawback, if we need to use too many library files, so the copy will be more troublesome, less efficient. We can use the second method.

The second kind : we can load the library files we need in our program, so we don't need to copy them to our own program directory. Let's illustrate with an example that I'm now going to refer to the API functions of the SQLite database in the program

Example:

New project: ZRL (Random), here is just a demo, so we create a new empty project, run it (generate the executable file)




1 Add a file reference to the Lib Static Library Path: Project---Properties---configuration PROPERTIES---linker---general---Additional Library directories: Add lib file directory. (Note: This file's directory refers to the last level of your library file directory, you must not bring your file name, here is only to store "library file directory", the same as)







2 then add a project reference to the Lib file name: Project---Properties---configuration PROPERTIES---linker---input---Additional dependencies: Add lib file name, this step is equivalent to adding #pragma comment (lib, "Xxx.lib") in the program




3 Add Project header file directory: Project---Properties---configuration properties---c/C + +---General---Additional Include Directories: Plus header files to store directories. In this example:



4 Adding a DLL dynamic library referenced by the project: Place the referenced DLL in the same directory as the project's executable file.

Or we can also do not add additional library directory, including the directory of two, we can also be in the project---properties---configuration properties---VC + + Properties-contains the directory to add the header file directory.


In the project---properties---configuration properties---VC + + Properties-Library directory Add the file directory where the library directory is located. However, you should still set additional dependencies (as in the above).

Also summarize the issues that arise when referencing third-party libraries:

1 If you set the error (spelling error, etc.) in the attached link library, or neither add nor use #pragmacomment (lib, "Xxx.lib") to set

This process error will appear link error, probably "undefined function xxx".

2 Library Directory Error: Is the directory that is looking for the. lib file. If the error is set, the link error will indicate "XXX.lib not found".

Once this is set up, we can use the function of the library we have added.


Use third-party library principles in VS (Configure SQLite database)

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.