收到 GCC 链接器错误:链接器输入文件未使用,因为链接未完成

发布于 2025-01-02 06:27:43 字数 1299 浏览 2 评论 0原文

我是编写 makefile 的初学者,但我的程序遇到了这个链接问题。基本上,当我尝试在远程计算机上构建它时,我收到了上述错误。 这是我的 makefile:

SRCS = gt_cfs.c gt_kthread.c gt_matrix.c gt_pq.c gt_signal.c gt_spinlock.c \
    gt_uthread.c red_black_tree.c stack.c misc.c

HDRS = gt_bitops.h gt_cfs.h gt_include.h gt_kthread.h gt_pq.h gt_signal.h \
    gt_tailq.h gt_uthread.h red_black_tree.h stack.h misc.h

OBJS = gt_cfs.o gt_kthread.o gt_matrix.o gt_pq.o gt_signal.o gt_spinlock.o \
    gt_uthread.o red_black_tree.o stack.o misc.o

CC = gcc

CFLAGS = -Wall -pedantic -lrt -lm

PROGRAM = cfs_gtthreads

.PHONY: clean

all: $(PROGRAM)

$(PROGRAM):     $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(PROGRAM)

gt_include.h:   gt_bitops.h gt_cfs.h gt_kthread.h gt_pq.h \
            gt_signal.h gt_tailq.h gt_uthread.h

gt_cfs.o:   gt_cfs.c 

gt_kthread.o:   gt_kthread.c 

gt_matrix.o:    gt_matrix.c 

gt_pq.o:    gt_pq.c

gt_signal.o:    gt_signal.c

gt_spinlock.o:  gt_spinlock.c 

gt_uthread.o:   gt_uthread.c 

red_black_tree.o:   red_black_tree.c

stack.o:        stack.c

clean:          
rm -f *.o *~ $(PROGRAM)

现在这段代码可以在我的笔记本电脑上运行,但我必须通过 SSH 在远程计算机上运行我的程序。无论如何,在那台机器上我遇到了这个错误,所以我很困惑为什么它无法链接两个库:数学和时间(-lm 和 -lrt)。 gcc版本不同,我的是4.5.2,集群机是4.1.2。我也在 Ubuntu 上运行我的集群,集群机器是 Red-Hat。我不知道什么差异会导致此错误,因为这些是标准库。任何帮助表示赞赏。

提前致谢。

I am beginner when it comes to writing makefiles but I am having this linking issue with my program. Basically I am getting the above error when I try to build it on a remote machine.
Here is my makefile:

SRCS = gt_cfs.c gt_kthread.c gt_matrix.c gt_pq.c gt_signal.c gt_spinlock.c \
    gt_uthread.c red_black_tree.c stack.c misc.c

HDRS = gt_bitops.h gt_cfs.h gt_include.h gt_kthread.h gt_pq.h gt_signal.h \
    gt_tailq.h gt_uthread.h red_black_tree.h stack.h misc.h

OBJS = gt_cfs.o gt_kthread.o gt_matrix.o gt_pq.o gt_signal.o gt_spinlock.o \
    gt_uthread.o red_black_tree.o stack.o misc.o

CC = gcc

CFLAGS = -Wall -pedantic -lrt -lm

PROGRAM = cfs_gtthreads

.PHONY: clean

all: $(PROGRAM)

$(PROGRAM):     $(OBJS)
    $(CC) $(CFLAGS) $(OBJS) -o $(PROGRAM)

gt_include.h:   gt_bitops.h gt_cfs.h gt_kthread.h gt_pq.h \
            gt_signal.h gt_tailq.h gt_uthread.h

gt_cfs.o:   gt_cfs.c 

gt_kthread.o:   gt_kthread.c 

gt_matrix.o:    gt_matrix.c 

gt_pq.o:    gt_pq.c

gt_signal.o:    gt_signal.c

gt_spinlock.o:  gt_spinlock.c 

gt_uthread.o:   gt_uthread.c 

red_black_tree.o:   red_black_tree.c

stack.o:        stack.c

clean:          
rm -f *.o *~ $(PROGRAM)

Now this code WORKS on my laptop but I have to run my program on a remote machine through SSH. Anyway on that machine is where I get this error, so I am confused as to why it can't link the two libraries: math and time (-lm and -lrt). The gcc versions are different, mine is 4.5.2 and the cluster machine is 4.1.2. I am also running mine on Ubuntu and the cluster machine is Red-Hat. I don't know what differences would cause this error since those are standard libraries. Any help is appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

捎一片雪花 2025-01-09 06:27:43

尝试将 LDFLAGS 变量与 -lrt -lm 一起使用,并将 $(LDFLAGS) 放在 $(OBJS) 之后。

Try using a LDFLAGS variable with -lrt -lm and put $(LDFLAGS) after the $(OBJS).

勿忘初心 2025-01-09 06:27:43

尝试将 $(CFLAGS) 放在该行的末尾。有时它会有所帮助。

Try to put $(CFLAGS) in the end of the line. Sometimes it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文