• linux libuv demo 编译 ,制作make文件


    在学习libuv框架时,编译使用它会出现各种各样的情况,现总结一下我发现的最佳实践

    • 第一步

    首先在github上去将代码下载到本地

    • 第二步

    假设现在你有一个项目是webserver,所在的目录是/tmp/webserver

     

    则你可以先到你第一步下载好的目录下,输入命令

    git archive --prefix="libuv/" HEAD | (cd /tmp/webserver ; tar -xf -)

    然后进入到/tmp/webserver下,看目录

     

    • 第三步

    进入到/tmp/webserver/libuv目录下,然后根据readme的要求进行编译

    ./autogen.sh
    ./configure
    make

    过程中,如果出现了什么报错,一般都是缺少了第三方工具,原则就是缺什么补什么就可以。

    执行完之后,你会发现在/tmp/webserver/libuv/.libs目录下,会出现很多文件,其中最重要的就是生成的静态连接库libuv.a

     

    • 第四步

    随便编写一个文件webserver.c

    // webserver.c
    // 只是为了可以运行起来
    #include <stdio.h>
    #include <uv.h>

    int64_t counter = 0;
    void wait_for_a_while(uv_idle_t* handle) {
    counter++;
    if (counter >= 10e6)
    uv_idle_stop(handle);
    }
    int main() {
    uv_idle_t idler;
    uv_idle_init(uv_default_loop(), &idler);
    uv_idle_start(&idler, wait_for_a_while);
    printf("Idling... ");
    uv_run(uv_default_loop(), UV_RUN_DEFAULT);
    uv_loop_close(uv_default_loop());
    return 0;
    }

    • 第五步

    编写Makefile

    UV_PATH=$(shell pwd)/libuv
    UV_LIB=$(UV_PATH)/.libs/libuv.a
    CFLAGS=-g -Wall -I$(UV_PATH)/include
    LIBS=

    uname_S=$(shell uname -s)

    ifeq (Darwin, $(uname_S))
    CFLAGS+=-framework CoreServices
    endif

    ifeq (Linux, $(uname_S))
    LIBS=-lrt -ldl -lm -pthread
    endif

    webserver: webserver.c
    gcc $(CFLAGS) -o webserver webserver.c $(UV_LIB) $(LIBS)

    运行make
    • 第六步

    ./webserver

  • 相关阅读:
    SWTDesigner注册器
    C# 创建、部署和调用WebService的简单示例
    (android实战)应用在线版本更新
    jQuery获取Select选择的Text和 Value(转)
    Android 判断sd卡和sim卡是否可用
    Android开发中如何固定屏幕显示!
    入侵网站简单方法总结
    【Android】防止UI界面被输入法遮挡(画面随输入法自适应)
    关于字符编码的问题
    最好用的mysql密码忘记的解决方法
  • 原文地址:https://www.cnblogs.com/iwana/p/13692392.html
Copyright © 2020-2023  润新知