如何使用不同路径中的特定库来制作Makefile?
我遇到的问题是我需要使用位于不同路径位置的特定库来编译我的代码。我需要使用 ./ramdisk/libs 路径中的 -lncurses 库,问题是该目录还包含我不想链接的 lthr 库版本。 makefile 从同一位置提取两个库,这不是我想要的。我无法更改文件系统中这些库目录的内容,因此我需要找到一种方法来告诉 Makefile 从路径 A 链接 lncurses 库并从路径 B 链接 lthr 库,而不是使用路径 A 中的 lthr 。
任何建议?
CC=icc
NCE=-L./ramdisk/libs
CFLAGS+=-I$(ROOTDIR)/../../include
#LDFLAGS=-static -lthr
$(DESTDIR)/nce: nce
mkdir -p $(DESTDIR)
$(INSTALL) -m 777 nce $(DESTDIR)
nce: nce.c
$(CC) $(CFLAGS) nce.c $(LDFLAGS) -o nce -lthr $(NCE) -lncurses
The issue I'm having is that I need to compile my code using specific libraries that are in different path locations. I need to use -lncurses library from ./ramdisk/libs path, the problem is that this directory also cointains a version of lthr library that I don't want to be linked. The makefile is pulling both libraries from the same location which is not what I want. I can't change the contents of these library directories in the filesystem, so I need to find a way to tell the Makefile to link lncurses library from path A and link lthr library from path B instead using the lthr from path A.
Any suggestions?
CC=icc
NCE=-L./ramdisk/libs
CFLAGS+=-I$(ROOTDIR)/../../include
#LDFLAGS=-static -lthr
$(DESTDIR)/nce: nce
mkdir -p $(DESTDIR)
$(INSTALL) -m 777 nce $(DESTDIR)
nce: nce.c
$(CC) $(CFLAGS) nce.c $(LDFLAGS) -o nce -lthr $(NCE) -lncurses
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您(可能)可以通过提供库存档的完整路径来绕过搜索。因此,您可以尝试
./ramdisk/libs/libncurses.a
(或其他),而不是指定 -lncurses 。您没有指定它是否是共享库,我不完全确定这适用于共享库,但可能值得一试。[编辑]
由于这是一个共享库问题,也许是这样的:
我有点在黑暗中拍摄,因为我不熟悉 icc,但想法是确保链接器将 thr 的路径放在运行时链接器的路径上在 ramdisk 上的路径之前搜索路径,以便首先在那里找到 thr。
You can (probably) bypass the search by giving the full path to the library archive. So instead of specifying
-lncurses
, you might try./ramdisk/libs/libncurses.a
(or whatever). You didn't specify whether it was a shared lib or not, and I'm not entirely sure that this works for shared libraries, but probably worth a try.[edit]
Since this is a shared lib issues, maybe something like:
I'm kind of shooting in the dark here as I'm not familiar with icc, but the idea is to make sure the linker puts thr's path on the runtime linker's search path before the one on the ramdisk so that thr gets found there first.
您可以将远程库复制到本地工作目录。
ncurses 将从一个位置获取资源,而 thr 将从另一位置获取资源。
You could copy the remote library to a local working directory.
ncurses would source from one location while thr would source from another.