configure pkg-config PKG_CONFIG_PATH(解释)

      1.什么是configure

      configure会根据传入的配置项目检查程序编译时所依赖的环境以及对程序编译安装进行配置,最终生成编译所需的Makefile文件供程序Make读入使用进而调用相关编译程式(通常调用编译程序都是gcc)来编译最终的二进制程序。而configure脚本在检查相应依赖环境时(例:所依赖软件的版本、相应库版本等),通常会通过pkg-config的工具来检测相应依赖环境。

      2.什么是pkg-config

      pkg-config用来检索系统中安装库文件的信息,典型的是用作库的编译和连接。一般来说,如果库的头文件不在/usr/include目录中,那么在编译的时候需要用-I参数指定其路径。由于同一个库在不同系统上可能位于不同的目录下,用户安装库的时候也可以将库安装在不同的目录下,所以即使使用同一个库,由于库的路径的不同,造成了用-I参数指定的头文件的路径和在连接时使用-L参数指定lib库的路径都可能不同,其结果就是造成了编译命令界面的不统一。可能由于编译,连接的不一致,造成同一份程序从一台机器copy到另一台机器时就可能会出现问题。
      pkg-config 就是用来解决编译连接界面不统一问题的一个工具。基本思想:pkg-config是通过库提供的一个.pc文件获得库的各种必要信息的,包括版本信息、编译和连接需要的参数等。需要的时候可以通过pkg-config提供的参数(–cflags, –libs),将所需信息提取出来供编译和连接使用。这样,不管库文件安装在哪,通过库对应的.pc文件就可以准确定位,可以使用相同的编译和连接命令,使得编译和连接界面统一。它提供的主要功能有:

<1> 检查库的版本号。如果所需库的版本不满足要求,打印出错误信息,避免连接错误版本的库文件。
<2> 获得编译预处理参数,如宏定义,头文件的路径。
<3> 获得编译参数,如库及其依赖的其他库的位置,文件名及其他一些连接参数。
<4> 自动加入所依赖的其他库的设置。

      在默认情况下,每个支持 pkg-config 的库对应的.pc文件在安装后都位于安装目录中的lib/pkgconfig目录下.新软件一般都会安装.pc文件,没有可以自己创建,并且设置环境变量PKG_CONFIG_PATH寻找.pc文件路径,否则怎么找得到呢。使用pkg-config工具提取库的编译和连接参数有两个基本的前提:

<1> 库本身在安装的时候必须提供一个相应的.pc文件。不这样做的库说明不支持pkg-config工具的使用。
<2> pkg-config必须知道要到哪里去寻找此.pc 文件。

      3.PKG_CONFIG_PATH.

      上边的第二个基本条件就是设置这个环境变量了。环境变量PKG_CONFIG_PATH是用来设置.pc文件的搜索路径的,pkg-config按照设置路径的先后顺序进行搜索,直到找到指定的.pc 文件为止。这样,库的头文件的搜索路径的设置实际上就变成了对.pc文件搜索路径的设置。在安装完一个需要使用的库后,比如Glib,一是将相应的.pc文件,如glib-2.0.pc拷贝到/usr/lib/pkgconfig目录下,二是通过设置环境变量PKG_CONFIG_PATH添加glib-2.0.pc文件的搜索路径。
      这样设置之后,使用Glib库的其它程序或库在编译的时候pkg-config就知道首先要到/opt/gtk/lib/pkgconfig这个目录中去寻找glib-2.0.pc了(GTK+和其它的依赖库的.pc文件也将拷贝到这里,也会首先到这里搜索它们对应的.pc文件)。之后,通过pkg-config就可以把其中库的编译和连接参数提取出来供程序在编译和连接时使用。另外还需要注意的是:环境变量的这种设置方式只对当前的终端窗口有效。如果到了没有进行上述设置的终端窗口中,pkg-config将找不到新安装的glib-2.0.pc文件、从而可能使后面进行的安装(如Glib之后的Atk的安装)无法进行。
  在我们采用的安装方案中,由于是使用环境变量对GTK+及其依赖库进行的设置,所以当系统重新启动、或者新开一个终端窗口之后,如果想使用新安装的GTK+库,需要如上面那样重新设置PKG_CONFIG_PATH和LD_LIBRARY_PATH环境变量。

  这种使用GTK+的方法,在使用之前多了一个对库进行设置的过程。虽然显得稍微繁琐了一些,但却是一种最安全的使用GTK+库的方式,不会对系统上已经存在的使用了GTK+库的程序(比如GNOME桌面)带来任何冲击。


hi.baidu.com/delovery/blog/item/4f9d8a1029ac1a1a213f2ec0.html


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
全志R40平台的tinav2.1系统下打开SPI2接口 1、(可选修改) Q:\r40_tinav2.1\spi20_r40_tinav2.1\lichee\brandy\build.sh build_uboot() { if [ "x${PLATFORM}" = "xsun50iw1p1" ] || \ [ "x${PLATFORM}" = "xsun50iw2p1" ] || \ [ "x${PLATFORM}" = "xsun50iw6p1" ] || \ [ "x${PLATFORM}" = "xsun50iw3p1" ] || \ [ "x${PLATFORM}" = "xsun8iw12p1" ] || \ [ "x${PLATFORM}" = "xsun8iw10p1" ] || \ [ "x${PLATFORM}" = "xsun8iw11p1" ]; then cd u-boot-2014.07/ else cd u-boot-2011.09/ fi make distclean if [ "x$MODE" = "xota_test" ] ; then export "SUNXI_MODE=ota_test" fi make ${PLATFORM}_config make -j16 #make spl #make fes if [ ${PLATFORM} = "sun8iw11p1" ]; then make distclean make ${PLATFORM}_nor_config make -j16 #make spl #make fes fi cd - 1>/dev/null } 2、 Q:\r40_tinav2.1\spi20_r40_tinav2.1\lichee\linux-3.10\drivers\spi\spidev.c static struct spi_driver spidev_spi_driver = { .driver = { .name = "spidev", .owner = THIS_MODULE, .of_match_table = of_match_ptr(spidev_dt_ids), }, .probe = spidev_probe, .remove = spidev_remove, /* NOTE: suspend/resume methods are not necessary here. * We don't do anything except pass the requests to/from * the underlying controller. The refrigerator handles * most issues; the controller driver handles the rest. */ }; 3、验证APP程序: Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\Makefile ############################################## # OpenWrt Makefile for helloworld program # # # Most of the variables used here are defined in # the include directives below. We just need to # specify a basic description of the package, # where to build our program, where to find # the source files, and where to install the # compiled program on the router. # # Be very careful of spacing in this file. # Indents should be tabs, not spaces, and # there should be no trailing whitespace in # lines that are not commented. # ############################################## include $(TOPDIR)/rules.mk # Name and release number of this package PKG_NAME:=spidev20_test PKG_VERSION:=0.0.1 PKG_RELEASE:=1 # This specifies the directory where we're going to build the program. # The root build directory, $(BUILD_DIR), is by default the build_mipsel # directory in your OpenWrt SDK directory PKG_BUILD_DIR := $(COMPILE_DIR)/$(PKG_NAME) include $(BUILD_DIR)/package.mk # Specify package information for this program. # The variables defined here should be self explanatory. # If you are running Kamikaze, delete the DESCRIPTION # variable below and uncomment the Kamikaze define # directive for the description below define Package/spidev20_test SECTION:=utils CATEGORY:=Allwinner TITLE:=spidev20_test just test the SPI2 interface DEPENDS:=+libpthread endef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above define Package/spidev20_test/description If you can't figure out what this program does, you're probably brain-dead and need immediate medical attention. endef # Specify what needs to be done to prepare for building the package. # In our case, we need to copy the source files to the build directory. # This is NOT the default. The default uses the PKG_SOURCE_URL and the # PKG_SOURCE which is not defined here to download the source from the web. # In order to just build a simple program that we have just written, it is # much easier to do it this way. define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/ endef define Build/Configure endef define Build/Compile $(MAKE) -C $(PKG_BUILD_DIR) \ CC="$(TARGET_CC)" \ CFLAGS="$(TARGET_CFLAGS)" -Wall \ LDFLAGS="$(TARGET_LDFLAGS)" \ LIBS="-lpthread" \ all endef # We do not need to define Build/Configure or Build/Compile directives # The defaults are appropriate for compiling a simple program such as this one # Specify where and how to install the program. Since we only have one file, # the helloworld executable, install it by copying it to the /bin directory on # the router. The $(1) variable represents the root directory on the router running # OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install # directory if it does not already exist. Likewise $(INSTALL_BIN) contains the # command to copy the binary file from its current location (in our case the build # directory) to the install directory. define Package/spidev20_test/install $(INSTALL_DIR) $(1)/bin $(INSTALL_BIN) $(PKG_BUILD_DIR)/spidev20_test $(1)/bin/ endef # This line executes the necessary commands to compile our program. # The above define directives specify all the information needed, but this # line calls BuildPackage which in turn actually uses this information to # build a package. $(eval $(call BuildPackage,spidev20_test)) Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\src\Makefile TARGET = spidev20_test INCLUDES += -I. -Icommon/ LIBS += -lpthread -lm -lrt SRCS = spidev20_test.c OBJS = $(SRCS:.c=.o) %.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< $(TARGET): $(OBJS) $(CC) -o $@ $(OBJS) $(LIBS) $(LDFLAGS) all:$(TARGET) clean: rm -rf $(TARGET) *.o *.a *~ cd common && rm -f *.o *.a *.bak *~ .depend Q:\r40_tinav2.1\spi20_r40_tinav2.1\package\allwinner\spidev20_test\src\spidev20_test.c /* * SPI testing utility (using spidev driver) * * Copyright (c) 2007 MontaVista Software, Inc. * Copyright (c) 2007 Anton Vorontsov <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License. * * Cross-compile with cross-gcc -I/path/to/cross-kernel/include */ #include <stdint.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <getopt.h> #include <fcntl.h> #include <sys/ioctl.h> #include <linux/types.h> #include <linux/spi/spidev.h> #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) static void pabort(const char *s) { perror(s); abort(); } //static const char *device = "/dev/spidev0.0"; //static const char *device = "/dev/spidev0.1"; static const char *device = "/dev/spidev2.0"; static uint8_t mode; static uint8_t bits = 8; static uint32_t speed = 500000; static uint16_t delay; static void transfer(int fd) { int ret; //uint8_t tx[] = { // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x40, 0x00, 0x00, 0x00, 0x00, 0x95, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xAD, // 0xF0, 0x0D, //}; // CityBrand WelCome U! uint8_t tx[] = { 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, 0x43, 0x69, 0x74, 0x79, 0x42, 0x72, 0x61, 0x6E, 0x64, 0x20, 0x57, 0x65, 0x6C, 0x43, 0x6F, 0x6D, 0x65, 0x20, 0x55, 0x21, }; uint8_t rx[ARRAY_SIZE(tx)] = {0, }; struct spi_ioc_transfer tr = { .tx_buf = (unsigned long)tx, .rx_buf = (unsigned long)rx, .len = ARRAY_SIZE(tx), .delay_usecs = delay, .speed_hz = speed, .bits_per_word = bits, }; ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr;); if (ret < 1) pabort("can't send spi message"); for (ret = 0; ret < ARRAY_SIZE(tx); ret++) { //if (!(ret % 6)) // puts(" "); //printf("%.2X ", rx[ret]); if (!(ret % 20)){ puts("\n"); } printf("%c", rx[ret]); } //puts(""); puts("\n"); } static void print_usage(const char *prog) { printf("Usage: %s [-DsbdlHOLC3]\n", prog); puts(" -D --device device to use (default /dev/spidev1.1)\n" " -s --speed max speed (Hz)\n" " -d --delay delay (usec)\n" " -b --bpw bits per word \n" " -l --loop loopback\n" " -H --cpha clock phase\n" " -O --cpol clock polarity\n" " -L --lsb least significant bit first\n" " -C --cs-high chip select active high\n" " -3 --3wire SI/SO signals shared\n"); exit(1); } static void parse_opts(int argc, char *argv[]) { while (1) { static const struct option lopts[] = { { "device", 1, 0, 'D' }, { "speed", 1, 0, 's' }, { "delay", 1, 0, 'd' }, { "bpw", 1, 0, 'b' }, { "loop", 0, 0, 'l' }, { "cpha", 0, 0, 'H' }, { "cpol", 0, 0, 'O' }, { "lsb", 0, 0, 'L' }, { "cs-high", 0, 0, 'C' }, { "3wire", 0, 0, '3' }, { "no-cs", 0, 0, 'N' }, { "ready", 0, 0, 'R' }, { NULL, 0, 0, 0 }, }; int c; c = getopt_long(argc, argv, "D:s:d:b:lHOLC3NR", lopts, NULL); if (c == -1) break; switch (c) { case 'D': device = optarg; break; case 's': speed = atoi(optarg); break; case 'd': delay = atoi(optarg); break; case 'b': bits = atoi(optarg); break; case 'l': mode |= SPI_LOOP; break; case 'H': mode |= SPI_CPHA; break; case 'O': mode |= SPI_CPOL; break; case 'L': mode |= SPI_LSB_FIRST; break; case 'C': mode |= SPI_CS_HIGH; break; case '3': mode |= SPI_3WIRE; break; case 'N': mode |= SPI_NO_CS; break; case 'R': mode |= SPI_READY; break; default: print_usage(argv[0]); break; } } } int main(int argc, char *argv[]) { int ret = 0; int fd; parse_opts(argc, argv); fd = open(device, O_RDWR); if (fd < 0) pabort("can't open device"); /* * spi mode */ ret = ioctl(fd, SPI_IOC_WR_MODE, &mode;); if (ret == -1) pabort("can't set spi mode"); ret = ioctl(fd, SPI_IOC_RD_MODE, &mode;); if (ret == -1) pabort("can't get spi mode"); /* * bits per word */ ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits;); if (ret == -1) pabort("can't set bits per word"); ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits;); if (ret == -1) pabort("can't get bits per word"); /* * max speed hz */ ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed;); if (ret == -1) pabort("can't set max speed hz"); ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed;); if (ret == -1) pabort("can't get max speed hz"); printf("spi mode: %d\n", mode); printf("bits per word: %d\n", bits); printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000); transfer(fd); close(fd); return ret; } 4、修改配置文件: Q:\r40_tinav2.1\spi20_r40_tinav2.1\target\allwinner\azalea-m2ultra\configs\sys_config.fex [jtag_para] jtag_enable = 1 jtag_ms = port:PB14<3><default><default><default> jtag_ck = port:PB15<3><default><default><default> jtag_do = port:PB16<3><default><default><default> jtag_di = port:PB17<3><default><default><default> 修改为: [jtag_para] jtag_enable = 0 ;jtag_ms = port:PB14<3><default><default><default> ;jtag_ck = port:PB15<3><default><default><default> ;jtag_do = port:PB16<3><default><default><default> ;jtag_di = port:PB17<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI controller configuration ;---------------------------------------------------------------------------------- [spi0] spi0_used = 0 spi0_cs_number = 2 spi0_cs_bitmap = 3 spi0_cs0 = port:PC23<3><1><default><default> spi0_cs1 = port:PI14<2><1><default><default> spi0_sclk = port:PC2<3><default><default><default> spi0_mosi = port:PC0<3><default><default><default> spi0_miso = port:PC1<3><default><default><default> [spi1] spi1_used = 0 spi1_cs_number = 2 spi1_cs_bitmap = 3 spi1_cs0 = port:PA0<3><1><default><default> spi1_cs1 = port:PA4<3><1><default><default> spi1_sclk = port:PA1<3><default><default><default> spi1_mosi = port:PA2<3><default><default><default> spi1_miso = port:PA3<3><default><default><default> [spi2] spi2_used = 0 spi2_cs_number = 2 spi2_cs_bitmap = 3 spi2_cs0 = port:PB14<2><1><default><default> spi2_cs1 = port:PB13<2><1><default><default> spi2_sclk = port:PB15<2><default><default><default> spi2_mosi = port:PB16<2><default><default><default> spi2_miso = port:PB17<2><default><default><default> [spi3] spi3_used = 0 spi3_cs_number = 2 spi3_cs_bitmap = 3 spi3_cs0 = port:PA5<3><1><default><default> spi3_cs1 = port:PA9<3><1><default><default> spi3_sclk = port:PA6<3><default><default><default> spi3_mosi = port:PA7<3><default><default><default> spi3_miso = port:PA8<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI device configuration ;compatible --- device name ;spi-max-frequency --- work frequency ;reg --- chip select ;optional properties: spi-cpha, spi-cpol, spi-cs-high ;---------------------------------------------------------------------------------- ;[spi0/spi_board0] ;compatible = ;spi-max-frequency = ;reg = ;spi-cpha ;spi-cpol ;spi-cs-high 修改为: ;---------------------------------------------------------------------------------- ;SPI controller configuration ;---------------------------------------------------------------------------------- ;spi0有接SPI器件(和PC引脚和NAND冲突),但是空贴! [spi0] spi0_used = 0 spi0_cs_number = 2 spi0_cs_bitmap = 3 spi0_cs0 = port:PC23<3><1><default><default> spi0_cs1 = port:PI14<2><1><default><default> spi0_sclk = port:PC2<3><default><default><default> spi0_mosi = port:PC0<3><default><default><default> spi0_miso = port:PC1<3><default><default><default> ;和gmac0复用冲突了! [spi1] spi1_used = 0 spi1_cs_number = 2 spi1_cs_bitmap = 3 spi1_cs0 = port:PA0<3><1><default><default> spi1_cs1 = port:PA4<3><1><default><default> spi1_sclk = port:PA1<3><default><default><default> spi1_mosi = port:PA2<3><default><default><default> spi1_miso = port:PA3<3><default><default><default> ;大排针J9引出来了! [spi2] spi2_used = 1 spi2_cs_number = 2 spi2_cs_bitmap = 3 spi2_cs0 = port:PB14<2><1><default><default> spi2_cs1 = port:PB13<2><1><default><default> spi2_sclk = port:PB15<2><default><default><default> spi2_mosi = port:PB16<2><default><default><default> spi2_miso = port:PB17<2><default><default><default> ;和gmac0复用冲突了! [spi3] spi3_used = 0 spi3_cs_number = 2 spi3_cs_bitmap = 3 spi3_cs0 = port:PA5<3><1><default><default> spi3_cs1 = port:PA9<3><1><default><default> spi3_sclk = port:PA6<3><default><default><default> spi3_mosi = port:PA7<3><default><default><default> spi3_miso = port:PA8<3><default><default><default> ;---------------------------------------------------------------------------------- ;SPI device configuration ;compatible --- device name ;spi-max-frequency --- work frequency ;reg --- chip select ;optional properties: spi-cpha, spi-cpol, spi-cs-high ;---------------------------------------------------------------------------------- ;[spi0/spi_board0] ;compatible = ;spi-max-frequency = ;reg = ;spi-cpha ;spi-cpol ;spi-cs-high [spi2/spi_board2] compatible = "spidev" spi-max-frequency = 50000000 reg = 0 ;spi-cpha = 0 ;spi-cpol = 0 ;spi-cs-high = 0 5、刷机之后: root@TinaLinux:/# root@TinaLinux:/# find . -name spi* ./bin/spidev20_test ./dev/spidev2.0 ./proc/irq/44/spi2 ./rom/bin/spidev20_test ./rom/usr/lib/opkg/info/spidev20_test.control ./rom/usr/lib/opkg/info/spidev20_test.list ./sys/bus/spi ./sys/bus/spi/devices/spi2.0 ./sys/bus/spi/drivers/spidev ./sys/bus/spi/drivers/spidev/spi2.0 ./sys/bus/platform/devices/spi2 ./sys/bus/platform/drivers/spi ./sys/bus/platform/drivers/spi/spi2 ./sys/devices/soc/spi2 ./sys/devices/soc/spi2/spi_master ./sys/devices/soc/spi2/spi_master/spi2 ./sys/devices/soc/spi2/spi_master/spi2/spi2.0 ./sys/devices/soc/spi2/spi_master/spi2/spi2.0/spidev ./sys/devices/soc/spi2/spi_master/spi2/spi2.0/spidev/spidev2.0 ./sys/class/spi_master ./sys/class/spi_master/spi2 ./sys/class/spidev ./sys/class/spidev/spidev2.0 ./sys/kernel/debug/clk/hosc/pll_periph0/spi2 ./sys/kernel/debug/clk/hosc/spi0 ./sys/kernel/debug/clk/hosc/spi1 ./sys/kernel/debug/clk/hosc/spi3 ./sys/module/spidev ./usr/lib/opkg/info/spidev20_test.control ./usr/lib/opkg/info/spidev20_test.list root@TinaLinux:/# root@TinaLinux:/#

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值