In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to use the dynamic link library generated by CAccord +". The content of the explanation in this article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the dynamic link library generated by CAccord +".
Operating environment: Visual Studio 2017
Although .NET Core is cross-platform, it is impossible to develop using C # everywhere, just as no one uses SQL to develop Android APP, and each language has its own advantages and limitations.
For sensors, 32-bit, 16-bit embedded devices, there may be only a few KB memory, those serial ports, pins, circuits, signals, can only be developed in C language. As far as Linux is concerned, Linux itself is developed in C language, which has rich interface support and compatibility for C language, and there are many places that can only use C language.
The underlying application can be completed in C language, what if you want to develop a website or a large application?
We can first write the underlying API interface in C language, generate .so dynamic link library, and then use C # to introduce C language dynamic link library. Use C language for underlying interface development, use .NET Core/C# to achieve cross-platform application development, through pre-defined API, you can control the overall situation.
First, install CAccord Category + support on Visual Studio 2017
The purpose of this step is to develop a set of programs on VS 2017. You can also use other tools to develop C language programs, or even write and compile them in vim in Linux.
Second, write a simple C language program and generate a dynamic link library
After creating the project, click Properties and select generate .so
Then create a new test.cpp file, right-create a new item, and the C language code is as follows
Extern "C" {}
Indicates that the method functions within {} can be used externally
Extern "C" {int Sum (int aline int b) {return a + b;}}
Right-generate
You will then be asked to add a Linux host connection. Actually, it is useless to add here, but vs must be added by you to generate and compile, which actually has no effect on our later operations.
Next, look at the picture operation.
Click generate menu bar-for projects only-link xxx only
Then the following output column will report an error, regardless of him, and then click on the project-right-generate
After that, the .so file will be generated, copied and stored.
Third, C# projects use this dynamic link library
Create a .NET Core project, copy the .so file in, and remember to "always copy"
Create a new class, the class name is not important, the main thing is that the method name and parameters should be consistent.
Head introduction
Using System.Runtime.InteropServices
The code for the class is as follows
Then use this type of library
Public class Test {[DllImport (". / libProject2.so", CallingConvention = CallingConvention.Cdecl)] public static extern int Sum (int apenint b);} class Program {static void Main (string [] args) {Console.WriteLine (Test.Sum (666666)) While (true) {Console.WriteLine ("enter two numbers separated by spaces, such as 666 666"); string [] vs = Console.ReadLine () .Split (""); int a = Convert.ToInt32 (vs [0]); int b = Convert.ToInt32 (vs [1]) Console.WriteLine (Test.Sum (afort b));}
Package and run in Linux after release
Thank you for your reading, the above is the content of "how to use the dynamic link library generated by Cpicket +". After the study of this article, I believe you have a deeper understanding of the problem of how to use the dynamic link library generated by Cplink +, and the specific use 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.