如何将子文件夹与C中的GCC联系起来?
我有以下树:
├── cminpack
│ ├── hybrd.c
│ ├── hybrd.o
│ ├── hybrj1.c
│ ├── hybrj1.o
│ ├── hybrj.c
│ ├── hybrj.o
│ ├── libminpack.a
│ ├── Makefile
│ ├── minpack.h
│ ├── minpack.h.gch
│ ├── readmeC.txt
│ ├── readme.txt
├── greeter.c
├── greeter.h
├── greeter.o
├── swaps.c
├── swaps.h
├── swaps.o
文件:
cminpack
是我找到并复制的软件包,我可以成功地make
它成功地swaps.c
是我的main
是,我也确实有以下内容:
#include "./cminpack/minpack.h"
#include "./greeter.h"
enterer.c
是另一个文件,其中
包含swaps.c
我调用函数来自forter.c
和函数hybrd _
来自cminpack/hybrd.c
。我想将同时enterer
和cminpack
链接到我的swaps
。
我设法通过运行以下GCC命令来链接entry
:
sudo gcc -c swaps.c enterer.c; sudo gcc -o swaps swaps swaps swaps swaps swaps.c engreter.c -lm; ./交换
现在,如果我尝试链接cminpack
我正在运行以下GCC命令:
sudo gcc -c swaps.c enter.c -i.c -i./cminpack; sudo gcc -o交换swaps.c enterer.c -lm -l /cminpack < /code>
这会导致臭名昭著的链接错误:
/usr/bin/ld: /tmp/ccxwxt6A.o: in function `fsolve':
swaps.c:(.text+0xfb3): undefined reference to `hybrd_'
collect2: error: ld returned 1 exit status
如何链接子文件夹?
(GCC版本10.2.1 20210110(Debian 10.2.1-6))
I have the below tree:
├── cminpack
│ ├── hybrd.c
│ ├── hybrd.o
│ ├── hybrj1.c
│ ├── hybrj1.o
│ ├── hybrj.c
│ ├── hybrj.o
│ ├── libminpack.a
│ ├── Makefile
│ ├── minpack.h
│ ├── minpack.h.gch
│ ├── readmeC.txt
│ ├── readme.txt
├── greeter.c
├── greeter.h
├── greeter.o
├── swaps.c
├── swaps.h
├── swaps.o
The files:
cminpack
is a package I found and copied and I canmake
it successfullyswaps.c
is where mymain
is, I also do have the below in it:
#include "./cminpack/minpack.h"
#include "./greeter.h"
greeter.c
is another file with some functions
In swaps.c
I call a function from greeter.c
and function hybrd_
from cminpack/hybrd.c
. I want to link both greeter
and cminpack
to my swaps
.
I manage to link greeter
by running the below gcc command:
sudo gcc -c swaps.c greeter.c ;sudo gcc -o swaps swaps.c greeter.c -lm ;./swaps
Now if I try to link cminpack
I am running the below gcc command:
sudo gcc -c swaps.c greeter.c -I./cminpack;sudo gcc -o swaps swaps.c greeter.c -lm -L /cminpack
This leads to the infamous linking error:
/usr/bin/ld: /tmp/ccxwxt6A.o: in function `fsolve':
swaps.c:(.text+0xfb3): undefined reference to `hybrd_'
collect2: error: ld returned 1 exit status
How do I link the subfolder?
(gcc version 10.2.1 20210110 (Debian 10.2.1-6))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除
-l cminpack
外,还应将-lminpack
添加到gcc
命令行。应该没有理由使用
sudo
进行此程序的汇编,如果您无法直接调用gcc
,则您的系统被错误配置并应修复。将编译器作为根而高度灰心。使用以下行中的主目录中创建
makefile
:In addition to
-L cminpack
, you should add-lminpack
to thegcc
command line.There should be no reason to use
sudo
for the compilation of this program, if you cannot invokegcc
directly, your system is misconfigured and should be fixed. Running the compiler as root is highly discouraged.Create a
Makefile
in the main directory with these lines: