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

How to use C++ static Library and dynamic Library

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "how to use C++ static library and dynamic library". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought. Let's study and learn how to use C++ static library and dynamic library.

Why did you write this tutorial?

This application model is often used in the development process, for example: as a senior programmer, you need to provide a wheel for the company's application development engineers: modbus communication library. After reading the modus protocol, you can implement the library manually, or you can make simple changes based on some third-party open source software (such as libmodbus) to get the job done more quickly.

If you choose the latter approach, wrap a layer of your defined API function around the libmodus library to output the library libNB.so that bears your name and provide it to the application developer.

But be sure to statically link to the libmodbus library in your libNB.so, so you only need to provide a libNB.so (.h header files are required, of course), and application developers will marvel: Daniel is Daniel, so it's done so quickly!

On the contrary, if you dynamically link to the libmodbus library, you have to provide two files to the application developer: libmodbus.so and libNB.so, which exposes the noble character of your laziness.

This tutorial is designed to demonstrate the compilation and linking process.

Of course, along with the introduction of some make+Makefile, cmake, VS2017 and other related knowledge.

What is included in the tutorial

1. Under the Linux platform

Compilation and use of dynamic Library and static Library

Indirect use of dynamic Library and static Library

Use make + Makefile to compile / build dynamic libraries, static libraries, applications

Use cmake to compile / build dynamic libraries, static libraries, applications.

2. Under the Windows platform

Compilation and use of dynamic Library and static Library

Export Mechanism of dynamic Library

Use cmake+VS2017 to compile / build dynamic libraries, static libraries, applications.

3. That's about what it looks like.

Video demonstration steps

1. Linxu platform

Demonstrate make + Makefile and cmake to do the following:

(1) libA output dynamic library, libB output dynamic library, compile executable program.

(2) libA output static library, libB output dynamic library, compile executable program.

2. Windows platform

Demonstrate using cmake to get the VS project, and then complete the following:

(1) libA output dynamic library, libB output dynamic library, compile executable program.

(2) libA output static library, libB output dynamic library, compile executable program.

(3) you can also test the remaining permutations and combinations yourself.

Thank you for your reading. the above is the content of "how to use C++ static Library and dynamic Library". After the study of this article, I believe you have a deeper understanding of how C++ static library and dynamic library are used. The specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report