Win7 under vs2010 compile using static and dynamic libraries

Source: Internet
Author: User

Knowledge Supplement:

Sqlite3.dll dynamic link library, which allows programs to share code and other resources that are necessary to perform special tasks.

Dynamic Sqlite3.lib is equivalent to an H file, which is a declaration of the export portion of the implementation section (. dll file). After compiling, only the part of the export declaration is compiled into the host program, and its generated sqlite3.exe requires the corresponding DLL file support at run time.

The static sqlite3.lib puts the export declaration and implementation in LIB. After compiling all the code is embedded in the host program, the generated Sqlite3.exe can be run directly.


Task:

I. Compile sqlite3 with VS2010 to generate dynamic Sqlite3.lib and Sqlite3.dll (Sqlite3.dll can also be downloaded in the official website). Write a simple program in VS2010, using dynamic sqlite3.lib and Sqlite3.dll.

Two. Compile sqlite3 using VS2010 to generate a static sqlite3.lib. Write a simple program in VS2010, using a static sqlite3.lib.


Task One:

1. Download Sqlite-amalgamation-3071000.zip on the SQLite website http://www.sqlite.org/download.html and Sqlite-dll-win32-x86-3071000.zip (this version I used).

2. Unzip each of the above two files to the respective folder (Sqlite3.def, Sqlite3.dll under the same folder Sqlite-dll).

3. From the installation directory of VS2010, locate the Lib.exe and Link.exe from Microsoft Visual Studio 10.0\vc\bin, VS2010 Visual Studio G:\Microsoft from the 10.0\ installation directory Common7\IDE found Mspdb100.dll. Place the Lib.exe link.exe Mspdb100.dll under the Sqlite-dll folder in step 2.

4. Open the cmd window and go to the above Sqlite-dll folder, mine is E:\SoftwareDesign\SQLite\sqlite-dll



5. Enter the command: lib/def:sqlite3.def/machine:ix86. At this point, Sqlite3.lib appears under the Sqlite-dll folder. (This is a dynamic Sqlite3.lib file, only 47KB in size.) )

6. Write a simple program in VS2010. FILE--New Project->win32 console application named Test1.

7. Replace the contents of Test1.cpp with the following code:

View Code

8. Copy sqlite3.h, Sqlite3.lib, Sqlite3.dll to the file directory where the project is located. Mine is E:\SoftwareDesign\SQLite\VisualStudio2010Workspace\Projects\test1\test1, as shown in:


9. In VS2010, right-test1 the project, add the existing item, and in the dialog box that appears, select Sqlite3.lib in the previous step. (The Lib file must be added to the project again)

10. Press F5 key to run successfully.

PS: At this point, to the project where the file directory found Test1.exe (size 29KB), mine is in E:\SoftwareDesign\SQLite\VisualStudio2010Workspace\Projects\test1\ Debug. If you run a direct double-click, you will be prompted to fail to run because of a missing sqlite3.dll file. This is because the dynamic sqlite3.lib only compiles the declarations to Test1.exe, and the runtime requires support for DLL files. Copy the Sqlite3.dll file to the Test1.exe same directory, and then double-click Run Test1.exe to run successfully.

Task Two:

1. In VS2010, the new Project->win32 project, file, named Sqlite3 (other names also line). In the wizard settings, select DLL (D), empty project.

2. Add the "Sqlite3.h", "sqlite3.c", "Sqlite3ext.h" three files in the downloaded Sqlite-amalgamation-3071000.zip to the project, as follows: Right-click Sqlite3 Engineering Add an existing item, and in the dialog box that appears, select the above three files.

3. (release version is smaller than the debug version, running fast, so I released the release version of the operation) as shown in:


4. Press the F7 key to compile (or right-click build). The Sqlite3.dll file is compiled in the file directory where the project is located. (PS: Some of the instructions on the web need to configure a lot of parameters and so on, tried many times are unsuccessful, but according to the above without unnecessary operation can be successful.) may be different for the VS or sqlite version of the reason)

5. The compilation will generate Sqlite3.obj files in the directory where the project is located, and mine is in E:\SoftwareDesign\SQLite\VisualStudio2010Workspace\Projects\sqlite3\ Under the Sqlite3\release. The next step is to use the Lib.exe file in the VS installation directory. Copy the Sqlite3.obj file to the directory where Lib.exe is located, my G:\Microsoft Visual Studio 10.0\vc\bin. Copy the Mspdb100.dll,mspdbcore.dll,mspdbsrv.exe,msobj100.dll under G:\Microsoft Visual Studio 10.0\common7\ide to the directory where Lib.exe is located.

6. Open the cmd window and go to the folder where Lib.exe is located, my G:\Microsoft Visual Studio 10.0\vc\bin. Input command: Lib Sqlite3.obj. A static sqlite3.lib (2.32MB size) is generated.


7. Write a simple program in VS2010. FILE--New Project->win32 console application named Test2.

Replace the code in the 8.test2.cpp with the code above. (The code in step 7 of the Task)

9. Copy the static sqlite3.lib generated in Sqlite3.h and step 6 to the file directory where the Test2 project is located, and mine is E:\SoftwareDesign\SQLite\VisualStudio2010Workspace\ Projects\test2\test2.

10. In VS2010, right-click Test2 Project, add Existing item. Select Sqlite3.lib.

11. Press F5 key to run successfully.

PS: At this point, the Test2.exe is generated under E:\SoftwareDesign\SQLite\VisualStudio2010Workspace\Projects\test2\Debug (501KB in size). Double-click to run directly. DLL file support is not required at this time. Because the static sqlite3.lib the export declaration and implementation are placed in the LIB, after compiling all the code is embedded in the Test2.exe, can run directly.

Win7 under vs2010 compile using static and dynamic libraries

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.