当前位置:网站首页>Installation and operation of libuv

Installation and operation of libuv

2022-06-24 12:15:00 ufgnix0802

Libuv Installation and operation of

Libuv Link to the official website of :http://libuv.org/

GitHub Download link :https://github.com/libuv/libuv

CMake Download link :https://cmake.org/download/

The following demo uses VS2022

Download and install

   Because the demonstration platform is Windows platform , That is to say CMake Compiled into visual studio Project to compile and run .

   After downloading Libuv The directory structure of the framework is as follows :

 design sketch

   Then , Use CMake Generate visual studio project .( open CMake) as follows :

 design sketch
 design sketch

   The following information can be installed by default .

 design sketch

   There is no need to uncheck the following , stay BUILD_TESTING and LIBUV_BUILD_TESTS There are the most basic modules in , For learning ( That is, if you have mastered Libuv frame , May cancel BUILD_TESTING and LIBUV_BUILD_TESTS Checked by ). Finally, click... Again Configure, Then click Generate. as follows :

 design sketch

   Final , You can click on the Open Project Open the project ( But we need to pay attention : If the computer has more than vs2022, There are other versions , May be opened in another version , It is better to find it directly build In the file directory sln file , Use the right mouse button vs2022 open

 design sketch

Run using

   Use vs2022 Open the interface as follows :

 design sketch

   Next is the key to project configuration , Please read and pay attention to .( The content is from the practice of bloggers , For reference only )

function uv_run_tests_a project ( Generate lib file )

TIPS: You can also try to run directly here uv_a Project generation uv_a.lib file ( Generated lib Same file ).

  Right click to run uv_run_tests_a project , as follows :

 design sketch
 design sketch

   The following results appear , Indicates successful operation .

 design sketch

   Where to open the file , We will find that there is more than exe file , And by what we need lib file , as follows :

 design sketch

   Next, create an empty project under the current solution , as follows :

 design sketch
 design sketch
 design sketch
 design sketch

   First , Create a new one .c file , as follows :

 design sketch
 design sketch

   And then right-click TestDemo01 project , The properties are configured with the following information :

 design sketch

TIPS: How to configure the output directory and intermediate directory of the project , Please refer to the following links , I'm just going to elaborate here :https://ufgnix0802.blog.csdn.net/article/details/121366990

The output directory :$(SolutionDir)\$(ProjectName)\bin/$(Platform)\$(Configuration)

Intermediate Directory :$(SolutionDir)\$(ProjectName)\temp/$(Platform)\$(Configuration)

   Then , Configure the following information :

 design sketch

TIPS:D:\libuv\include The included libraries must be imported , Of course, the same configuration principle as the output directory and the intermediate directory can also be used for the path ( Bloggers do not demonstrate here ).

   There are also items that need to be configured , as follows :

 design sketch
 design sketch

The contents to be added are :

iphlpapi.lib
userenv.lib
psapi.lib
ws2_32.lib
libs\uv_a.lib

 design sketch

TIPS: Note after confirmation , Be sure to click apply , Same as above .

   among , Last item libs\uv_a.lib, We need to use it until we run uv_run_tests_a Generated by the project lib file , Generate a... Under the current project libs Folder , Put the following file .

 design sketch
 design sketch

   Finally, we need to introduce task.h Header file into the current project , as follows ( The document can be obtained from libuv/test Look in the directory ):

 design sketch

   Copy to TestDemo01 In the project , as follows ( And will task.h Added to the TestDemo01 project ):

 design sketch
 design sketch

Running practice

   take libuv/test In the catalog echo-server.c Copy the contents of the file to main.c in , as follows :

 design sketch
 design sketch

   Last in main.c In the definition of main function , The contents are as follows :

int main()
{
    
    run_helper_tcp4_echo_server();// Call mode one , Call macro function 
    // Call mode 2 , Copy the macro function code directly 
    /* loop = uv_default_loop(); if (tcp4_echo_start(TEST_PORT)) return 1; notify_parent_process(); uv_run(loop, UV_RUN_DEFAULT); */
    return 0;
}

   Set the project to start project , The operation results are as follows :

 design sketch

   The generated file information is as follows :

 design sketch

   Here's how to use sokit The effect of the client terminal simulated by the tool :

 design sketch

原网站

版权声明
本文为[ufgnix0802]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240953200785.html