首页 > 解决方案 > 尝试在 Linux 上使用“gcc -L”将库添加到“C”中的项目 - 错误

问题描述

嗨,我正在尝试将一个库添加到我的 C 项目中以执行类任务,但我无法让它工作。

当我使用gcc -L ../build/lib ./bigint/src -lbigint它时显示错误:

/usr/bin/ld: ./bigint/src/ can not be found: File format not recognized
/usr/bin/ld: -lbigint can not be found
collect2: error: ld returned 1 exit status

我的目录看起来像这样:

root <- here im in the terminal trying, using the command
- bigint
-- src
--- bigint.c
--- bigint.h
--- bigint.h.gch
--- bigint.o
--- libbigint.a
--- support.h
--- support.g.gch
-- tst
- project.c
- project.h
...

标签: c

解决方案


-L每个 lib 目录都需要一个单独的目录。假设你真的想./bigint/src成为一个 lib 目录:

gcc -L ../build/lib -L ./bigint/src <C file or object file> -lbigint

推荐阅读