ar x libxxx.a gcc -shared -o libxxx.so *.o报错/usr/bin/gcc-linaro-5.3-2016.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/5.3.1/../../../../arm-linux-gnueabihf/bin/ld: buffer_frame.o: relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC buffer_frame.o: error adding symbols: 错误的值 collect2: error: ld returned 1 exit status
时间: 2023-07-23 13:20:30 浏览: 72
这个错误是由于在编译时缺少 -fPIC 选项导致的。-fPIC 选项是编译动态链接库时必须加上的选项之一。在重新编译时,你需要使用以下命令:
```
gcc -fPIC -c *.c
ar rcs libxxx.a *.o
gcc -shared -o libxxx.so *.o
```
这将在编译时添加 -fPIC 选项,并生成静态链接库和动态链接库。
相关问题
/usr/bin/ld: cannot find -lfreetyped
根据引用[1]和引用的内容,当编译程序时出现"/usr/bin/ld: cannot find -lxxx"的错误时,意味着编译器无法找到名为"libxxx.so"或"libxxx.a"的库文件。在这种情况下,我们需要确保库文件存在于正确的路径中。
对于"/usr/bin/ld: cannot find -lfreetype"的错误,我们需要确保freetype库文件存在于正确的路径中。可以按照以下步骤进行操作:
1. 首先,确认你已经安装了freetype库。可以使用以下命令来检查:
```shell
dpkg -l | grep freetype
```
2. 如果freetype库未安装,可以使用以下命令来安装:
```shell
sudo apt-get install libfreetype6-dev
```
3. 如果freetype库已安装,但是编译器仍然无法找到它,可能是因为库文件路径不正确。可以尝试将库文件拷贝到正确的路径中。假设你已经找到了freetype库文件"libfreetype.so"或"libfreetype.a",可以使用以下命令将其拷贝到/usr/lib/目录中:
```shell
sudo cp /path/to/libfreetype.so /usr/lib/
```
4. 完成上述步骤后,重新编译程序,应该不再出现"/usr/bin/ld: cannot find -lfreetype"的错误。
/usr/bin/ld: cannot find -lxxx 问题排查
当编译器提示"/usr/bin/ld: cannot find -lxxx"错误时,这通常意味着编译器无法找到指定的库文件。这可能是由于以下几个原因导致的:
1. 库文件不存在:首先,请确保指定的库文件存在于系统中。您可以使用以下命令来确认库文件是否存在:
```shell
ls /path/to/library
```
如果库文件不存在,请检查路径是否正确,并确保库文件已正确安装。
2. 库文件路径未正确指定:编译器需要知道库文件的位置。您可以使用以下方法之一来指定库文件的路径:
- 使用`-L`选项指定库文件的路径:
```shell
gcc main.c -L/path/to/library -lxxx -o test
```
- 将库文件复制到默认的库文件搜索路径中:
```shell
sudo cp /path/to/library /usr/lib
gcc main.c -lxxx -o test
```
3. 库文件名错误:请确保您正确指定了库文件的名称。库文件名应该是以`lib`开头,后面跟着库的名称,以及`.a`或`.so`扩展名。例如,如果库文件名为`libxxx.a`,则应该使用以下命令来编译:
```shell
gcc main.c -lxxx -o test
```
请根据上述建议检查您的编译命令,并确保库文件存在于正确的位置,并正确指定了库文件的路径和名称。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)