当前位置:网站首页>makefile 中指定程序运行时加载的库文件路径
makefile 中指定程序运行时加载的库文件路径
2022-07-27 14:37:00 【xhoufei2010】
1 问题描述
程序运行时,提示找不到库。
原因:默认运行加载的库路径为 /usr/lib
2 解决方法
2.1 方法一,设置PATH环境变量
如何在加入这些路径呢?以PATH变量为例。
一种方法是:直接在命令行下:
PATH="PATH:/path/to/your/bin:/another/path/to/bin”
$ export PATH
这种方法的好处是方便,立即生效,缺点是把当前会话或shell关了之后就失效了,下次还得运行一遍。
2.2 方法二, 修改makefile,直接指定路径
另一种方法是:makefile 中增加运行程序的库文件路径
LDFLAGS+= -Wl,-Bstatic -lbt
LDFLAGS+= -Wl,-rpath=/opt/lib/
LDDIR+=-Lhost/libbt/lib
CC=/opt/toolchain/arm-2012.03/bin/arm-none-linux-gnueabi-gcc
编译指令:
(CC)(LDDIR) -o @^ $(LDFLAGS)
3 makefile 相关参数说明
CFLAGS 表示用于 C 编译器的选项,
CXXFLAGS 表示用于 C++ 编译器的选项。
这两个变量实际上涵盖了编译和汇编两个步骤。
先来看几个相关的环境变量:PATH、LDFLAGS、CFLAGS
LDFLAGS:gcc 等编译器会用到的一些优化参数,也可以在里面指定库文件的位置。用法:LDFLAGS=“-L/usr/lib -L/path/to/your/lib”。每安装一个包都几乎一定的会在安装目录里建立一个lib目录。如果你明明安装了某个包,而安装另一个包时,它愣是说找不到,那就把那个包的lib路径加入的LDFALGS中试一下。
CFLAGS:和LDFLAGS类似,只不过要向里加如的是头文件(.h文件)的路径,如:CFLAGS=“-I/usr/include -I/path/to/your/include”。同样地,安装一个包时会在安装路径下建立一个include目录,当安装过程中出现问题时,试着把以前安装的包的include目录加入到该变量中来。
边栏推荐
- C language: data storage
- It is said that the US government will issue sales licenses to Huawei to some US enterprises!
- C语言:字符串函数与内存函数
- [sword finger offer] interview question 51: reverse pairs in the array - merge sort
- Interview focus - TCP protocol of transport layer
- Insert sort directly
- Extended log4j supports the automatic deletion of log files according to time division and expired files
- 聊聊面试必问的索引
- JS uses unary operators to simplify string to number conversion
- Implement custom spark optimization rules
猜你喜欢

C语言:字符串函数与内存函数

What format is this data returned from the background
![[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN](/img/01/bbf81cccb47b6351d7265ee4a77c55.png)
[sword finger offer] interview question 42: the maximum sum of continuous subarrays -- with 0x80000000 and int_ MIN

Summer Challenge harmonyos realizes a hand-painted board

Network principle (1) - overview of basic principles

Division of entity classes (VO, do, dto)

C语言:动态内存函数
![[sword finger offer] interview question 50: the first character that appears only once - hash table lookup](/img/72/b35bdf9bde72423410e365e5b6c20e.png)
[sword finger offer] interview question 50: the first character that appears only once - hash table lookup

C language: minesweeping games

Using Lombok results in the absence of parent class attributes in the printed toString
随机推荐
C language: data storage
Breaking through soft and hard barriers, Xilinx releases Vitis unified software platform for developers
Catalog component design and custom extended catalog implementation in spark3
[正则表达式] 匹配多个字符
Analysis of spark task scheduling exceptions
Complexity analysis
数据表的约束以及设计、联合查询——8千字攻略+题目练习解答
[sword finger offer] interview question 52: the first common node of two linked lists - stack, hash table, double pointer
Implementation of spark lazy list files
[正则表达式] 匹配分组
Use deconstruction to exchange the values of two variables
Summary of network device hard core technology insider router (Part 2)
网络设备硬核技术内幕 路由器篇 小结(下)
Read the wheelevent in one article
禁令之下,安防巨头海康与大华的应对之策!
[Yunxiang book club issue 13] common methods of viewing media information and processing audio and video files in ffmpeg
C: What is the return value (revolution) in a function
Spark 3.0 adaptive execution code implementation and data skew optimization
【剑指offer】面试题54:二叉搜索树的第k大节点
43亿欧元现金收购欧司朗宣告失败!ams表示将继续收购