Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Dynamic Library and static Library (Windows) in C++

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Library:

Using the technology of Library, compiled symbols can be made available to third parties.

There are two types of libraries:

1. Dynamic library Dynamic-Link Library (DLL) (called Shared Library under Linux)

2. Static library Static Library

I. creation and use of dynamic libraries

Create a DLL:

Create a console project of type "dll" with VC, and VC will automatically create a project framework for DLL

It automatically generates a DllMain function, which can be compared to the main function in ordinary applications.

VC project settings:

1. Cancel the "precompiled header file"

2. Change it to "/ MTd compilation"

3. Modify the name of the output DLL (my.dll)

Compile to get * .lib and * .dll, where:

* .dll:

Contains instructions compiled into all the code

* .lib: contains a list of the symbols contained in the table name my.dll and the location of each symbol in the dll. (exported symbol)

So, * .lib is much smaller than the file size of * .dll

If you want to export a global function, declare it with the keyword _ _ declspec (dllexport)

Note: this is a keyword specific to VC platform and is not available on linux platform.

The use is as follows:

Template _ declspec (dllexport) void MySwap (T & obj1, T & obj2) {T tmp = obj1; obj1 = obj2; obj2 = tml;}

Use dll:

# pragma comment (lib, "12_18_DLL01") _ declspec (dllimport) int Add (int a, int b); int main () {int ret = Add (1,2); std::cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report