《智能系统与技术丛书 深度学习实践:基于Caffe的解析》—2.8其他库的安装

举报
华章计算机 发表于 2019/06/02 01:33:22 2019/06/02
【摘要】 本书摘自《智能系统与技术丛书 深度学习实践:基于Caffe的解析》一文中的第2章,第2.8.1节,作者是薛云峰。

2.8 其他库的安装

2.8.1 LMDB的编译与安装

     LMDB的下载网址为https://github.com/LMDB/lmdb,下载后解压缩,编译LMDB的过程如下。

     1)打开VS2013,新建一个名称为lmdb的空项目,如图2-39所示。

image.png

图 2-39

      2)选择静态库链接,如图2-40所示。

image.png

图 2-40

      3)将lmdb中的以下几个“.c”文件和“.h”文件加入到此项目中,如图2-41所示。

image.png

      4)在刚才建立的工程中新建getopt.c和getopt.h的文件,添加如下代码。

getopt.c

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "getopt.h"

static const char* ID = "$Id: getopt.c,v 1.2 2003/10/26 03:10:20 vindaci Exp $";


char* optarg = NULL;

int optind = 0;

int opterr = 1;

int optopt = '?';

static char** prev_argv = NULL;

static int prev_argc = 0;

static int argv_index = 0;

static int argv_index2 = 0;

static int opt_offset = 0;

static int dashdash = 0;

static int nonopt = 0;

static void increment_index()

{

    if (argv_index < argv_index2)

    {

        while (prev_argv[++argv_index] && prev_argv[argv_index][0] != '-'

            && argv_index < argv_index2 + 1);

    }

    else argv_index++;

    opt_offset = 1;

}

static int permute_argv_once()

{

    if (argv_index + nonopt >= prev_argc) return 1;

    else

    {

        char* tmp = prev_argv[argv_index];


        memmove(&prev_argv[argv_index], &prev_argv[argv_index + 1],

            sizeof(char**) * (prev_argc - argv_index - 1));

        prev_argv[prev_argc - 1] = tmp;

        nonopt++;

        return 0;

    }

}

int getopt(int argc, char** argv, char* optstr)

{

    int c = 0;

    if (prev_argv != argv || prev_argc != argc)

    {

        prev_argv = argv;

        prev_argc = argc;

        argv_index = 1;

        argv_index2 = 1;

        opt_offset = 1;

        dashdash = 0;

        nonopt = 0;

    }

getopt_top:

    optarg = NULL;

    if (argv[argv_index] && !strcmp(argv[argv_index], "--"))

    {

        dashdash = 1;

        increment_index();

    }

    if (argv[argv_index] == NULL)

    {

        c = -1;

    }

    else if (dashdash || argv[argv_index][0] != '-' || !strcmp(argv[argv_index], "-"))

    {

        if (optstr[0] == '-')

        {

            c = 1;

            optarg = argv[argv_index];

            increment_index();

        }

        else if (optstr[0] == '+' || getenv("POSIXLY_CORRECT"))

        {

            c = -1;

            nonopt = argc - argv_index;

        }

        else

        {

            if (!permute_argv_once()) goto getopt_top;

            else c = -1;

        }

    }

    else

    {

        char* opt_ptr = NULL;

        c = argv[argv_index][opt_offset++];

        if (optstr[0] == '-') opt_ptr = strchr(optstr + 1, c);

        else opt_ptr = strchr(optstr, c);

        if (!opt_ptr)

        {

            if (opterr)

            {

                fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c);

            }

            optopt = c;

            c = '?';

            increment_index();

        }

        else if (opt_ptr[1] == ':')

        {

            if (argv[argv_index][opt_offset] != '\0')

            {

                optarg = &argv[argv_index][opt_offset];

                increment_index();

            }

            else if (opt_ptr[2] != ':')

            {

                if (argv_index2 < argv_index) argv_index2 = argv_index;

                while (argv[++argv_index2] && argv[argv_index2][0] == '-');

                optarg = argv[argv_index2];

                if (argv_index2 + nonopt >= prev_argc) optarg = NULL;

                increment_index();

            }

            else

            {

                increment_index();

            }

            if (optarg == NULL && opt_ptr[2] != ':')

            {

                optopt = c;

                c = '?';

                if (opterr)

                {

                    fprintf(stderr, "%s: option requires an argument -- %c\n",

                        argv[0], optopt);

                }

            }

        }

        else

        {

            if (argv[argv_index][opt_offset] == '\0')

            {

                increment_index();

            }

        }

    }


    if (c == -1)

    {

        optind = argc - nonopt;

    }

    else

    {

        optind = argv_index;

    }

    return c;

}


getopt.h

#ifndef GETOPT_H_

#define GETOPT_H_


#ifdef __cplusplus

extern "C" {

#endif

    extern char* optarg;

    extern int optind;

    extern int opterr;

    extern int optopt;

    int getopt(int argc, char** argv, char* optstr);

#ifdef __cplusplus

}

#endif

#endif


Unistd.h


#ifndef _UNISTD_H

#define _UNISTD_H 

#include <io.h> 

#include <process.h> 

#endif

/* _UNISTD_H */

     5)配置x64选项,如图2-42所示。

image.png

图 2-42

     6)修改属性,将C/C++下的SDL检查设置为否(/sdl-),如图2-43所示。

     7)添加到预处理定义宏,如图2-44所示。

     8)开始编译,如图2-45所示。

 image.png

图 2-43

image.png

图 2-44

 image.png

图 2-45

      9)分别在Debug和Release下编译,生成lmdb.lib库(如图2-46所示),并将该库与相应的头文件复制到相应的目录下,至此,LMDB的编译完成。

image.png


【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。