mac 编译源码 安装 查库

mac编译源码与安装 

我们以openssl为例。

  1. 从github上下载压缩文件https://github.com/openssl/openssl
  2. 解压缩  tar zxvf xxxxx.tar.gz
  3. ./configure --prefix=/usr/local/Cellar/openssl

  4. sudo make 

  5. sudo make install 

  6. 最关键的一步 export PKG_CONFIG_PATH=$(find /usr/local/Cellar -name 'pkgconfig' -type d | grep lib/pkgconfig | tr '\n' ':' | sed s/.$//) 配置环境变量

 

我们总是可以用brew install 安装具体的库 

 

查看库的依赖与头文件

pkg-config --libs --cflags xxxxx

执行这条命令后会展示出当前库的头文件与库所在的位置。

 

Xcode添加库无法好到/usr/local目录。

可以如下操作

按下CMD + Shift + G,然后输入“/usr/local/xxxxx”,之后选择libxxx.dylib文件。 
 

编译C代码加库

  • 第一种clang -g -o  xxxxx  xxxxx.c `pkg-config --libs --cflags  lib库名字`
  • 第二种clang -g -o  xxxxx  xxxxx.c  -I/usr/local/include -L/usr/local/lib -l库名字

Visual Studio Code 添加库文件

 

clang下代码的调试

https://www.cnblogs.com/yongfengnice/p/6784993.html

 


版权声明:本文为qq_15255121原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。