不论是windows下的程序,还是linux下的程序,开发环境都离不开三个目录:include、lib、bin,分别是头文件目录、库文件目录、运行文件目录。或许目录不叫这个名字,但却必不可少,除非你的程序是运行在虚拟机上或脚本文件如java、php、lua等。

  在windows下,可以不怎么关注这些东西,因为VS安装后默认了配置好了这些路径,如D:\Program Files\Microsoft SDK\include,如果使用到一些开源的库,在VS下设置就好了。并且windows下程序运行时,如果在系统的dll(相当于lib了,只是封装为dll),目录下找不到相关dll,会查找当前目录下是否有相应的dll,所有很多windows下的程序把自己的dll放到当前程序目录下就OK了。

  然而linux并不这么容易。一个原因是linux下没有像VS一样统一的IDE(Qt creator、code::block不错,但很多人不习惯用),都用gcc、g++来编译,如果不熟悉linux下这三个目录,让程序跑起来可能有点困难。尤其是使用了许多开源库的时候。

  linux的include默认有两个(可能有我不知道的吧),分别是/usr/include、/usr/local/include,gcc中用参数 -I可以指定其他目录

  lib目录默认则有三个,分别是/lib、/usr/lib、/usr/local/lib,gcc中用-L可以指定其他目录

  bin目录默认也有三个,分别是/bin、、/usr/bin、usr/local/bin。当然你可以用包含路径的指令来运行程序。

  当你编译一个开源的库时,如libev,在make install时(编译过程见另一篇随笔),通常会告诉你一些信息,如:

Libraries have been installed in:
/usr/local/lib If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.

  这就是告诉你,库文件安装到了/usr/local/lib文件夹里。可是当我编译链接下面的代码时,却发生了错误:

#include <ev.h>
#include <stdio.h> ev_io stdin_watcher;
ev_timer timeout_watcher; static void stdin_cb(EV_P_ ev_io *w,int revents)
{
puts ("stdin ready");
ev_io_stop(EV_A_ w);
ev_break (EV_A_ EVBREAK_ALL);
} static void timeout_cb (EV_P_ ev_timer *w,int revents)
{
puts ("timeout");
ev_break( EV_A_ EVBREAK_ONE );
} int main(int argc,char* argv[])
{
struct ev_loop *loop = EV_DEFAULT; ev_io_init(&stdin_watcher,stdin_cb,,EV_READ);
ev_io_start (loop,&stdin_watcher); ev_timer_init (&timeout_watcher,timeout_cb,5.5,); // in document the last is 0. not 0,I don't know why yet
ev_timer_start (loop,&timeout_watcher); ev_run (loop,); return ;
} output:
root@debian:/home/xzc/cpp/test# gcc -o libev_hello libev_hello.c
/tmp/ccNN2QkE.o: In function `stdin_cb':
libev_hello.c:(.text+0x20): undefined reference to `ev_io_stop'
libev_hello.c:(.text+0x33): undefined reference to `ev_break'
/tmp/ccNN2QkE.o: In function `timeout_cb':
libev_hello.c:(.text+0x5a): undefined reference to `ev_break'
/tmp/ccNN2QkE.o: In function `main':
libev_hello.c:(.text+0x71): undefined reference to `ev_default_loop'
libev_hello.c:(.text+0xc9): undefined reference to `ev_io_start'
libev_hello.c:(.text+0x11f): undefined reference to `ev_timer_start'
libev_hello.c:(.text+0x133): undefined reference to `ev_run'
collect2: ld returned exit status

正确的编译方法为gcc -o libev_hello libev_hello.c -lev,为什么要加-lev呢,参考gcc参数-llibrary,即需要指定ev库(就是libev)。这里我有点不明白,为什么我指定了头文件#include<ev.h>,链接时gcc没有自动去查找库libev.o,这个库已经被安装到/usr/local/lib里了。并且,我指定ev库,gcc怎么知道去哪个.o文件查找,难道根据名字,ev就是libev.o,如果是test,那就是libtest.o么。好吧,在没有找到答案之前,我就这样认为。

分析linux下的编译环境的更多相关文章

  1. FFmpeg在Linux下安装编译过程

    转载请把头部出处链接和尾部二维码一起转载,本文出自:http://blog.csdn.net/hejjunlin/article/details/52402759 今天介绍下FFmpeg在Linux下 ...

  2. Linux下搭建PHP环境

    转载于: http://www.uxtribe.com/php/405.html 该站下有系列PHP文章. 在Linux下搭建PHP环境比Windows下要复杂得多.除了安装Apache,PHP等软件 ...

  3. Java学习心得之 Linux下搭建JavaWeb环境

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 Java学习心得之 Linux下搭建JavaWeb环境 1. 前言2. Java安装3. t ...

  4. LINUX下文件编译

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  5. ACE-6.1.0 linux 下的编译与安装步骤

    ACE-6.1.0 linux 下的编译与安装步骤  引用至http://www.cnblogs.com/liangxiaxu/archive/2013/03/07/2948417.html 1.从  ...

  6. linux下搭建lamp环境以及安装swoole扩展

    linux下搭建lamp环境以及安装swoole扩展   一.CentOS 6.5使用yum快速搭建LAMP环境 准备工作:先更新一下yum源  我安装的环境是:apache2.2.15+mysql5 ...

  7. Linux下nginx编译安装教程和编译参数详解

    这篇文章主要介绍了Linux下nginx编译安装教程和编译参数详解,需要的朋友可以参考下 一.必要软件准备1.安装pcre 为了支持rewrite功能,我们需要安装pcre 复制代码代码如下: # y ...

  8. linux下配置python环境 django创建helloworld项目

    linux下配置python环境 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstal ...

  9. Linux下c语言环境概述

    Linux下C语言环境概述 主要涉及编辑器.编译链接器.调试器.项目管理工具 编辑器 Linux中常用的编辑器有vi和emacs 查看vim配置文件并编辑 编译链接器 在Linux中,最常用的编译器是 ...

随机推荐

  1. (转)iOS7界面设计规范(13) - UI基础 - 与iOS的系统整合

    突然就到了周日傍晚.你永远不会知道自己的生活在接下来的一周当中能够发生多少变化:各种不可预知性所带来的更多是快感还是焦虑与不安,冷暖自知.相比之下,白天工作当中那些需求列表与排期文档就显得那么可爱了, ...

  2. Servlet实现文件的下载

    (1)项目的主文件夹例如以下:(演示出image和servlet的位置所在) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGxnZW4xNTczODc= ...

  3. StretchDIBits使用方法

    转自:http://blog.csdn.net/giantchen547792075/article/details/6996011 StretchDIBits 函数把DIB.JPEG.PNG图像中一 ...

  4. 单片机C语言中标志位的经典应用

    /* 本例程是C语言的位域操作示例 这里为什么位域结构体与联合体一起使用? -->因为这样定义后,即可以单独使用标志位 也可同时使用整个字节数据 主要应用:单片机C语言 好处:用标志位可以节省R ...

  5. BGP

    http://network.51cto.com/art/200912/172439.htm http://blog.sina.com.cn/s/blog_b457dde80101cyqr.html ...

  6. python网络编程之socket

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  7. 【转载】CocoaPods安装和使用教程

    转自:http://code4app.com/article/cocoapods-install-usage 目录 CocoaPods是什么? 如何下载和安装CocoaPods? 如何使用CocoaP ...

  8. oracle datetime

    to_date('" + Convert.ToDateTime(TCRQ).ToString("yyyy-MM-dd")+"','YYYY-MM-DD'), C ...

  9. C# 获取远程xml文件

    /// <summary> /// 加载远程XML文档 /// </summary> /// <param name="URL"></pa ...

  10. c语言构建动态数组

    #include <stdio.h> #include <stdlib.h> int main(void) { int len; int * arr; printf(" ...