Makefile-找不到共享库 [英] Makefile - cannot find shared library

查看:124
本文介绍了Makefile-找不到共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于c ++ Linux项目的Makefile:

I have a Makefile for a c++ Linux project:

MODE ?= dbg
DIR = ../../../../../somdir/$(MODE)

SRC_FILES = a.cpp b.cpp
H_FILES = a.h

LDFLAGS += -L$(DIR)/lib/linux '-Wl,-R$$ORIGIN'
CPPFLAGS = -I$(DIR)/include
LIBRARIES = -lsomeso

ifeq (rel, $(MODE))
  CFLAGS = -Wall -g -DNDEBUG
else
  CFLAGS = -Wall -ansi -pedantic -Wconversion -g -DDEBUG -D_DEBUG
endif

sample: $(SRC_FILES) $(H_FILES) Makefile
    g++ $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBRARIES) $(SRC_FILES) -o sample

当我运行'make'时,它会构建项目,没有错误. 但是当我运行该项目时,它抱怨:

when i run 'make' it builds the project, with no errors. but when i run the project it complains that:

error while loading shared libraries: libsomeso.so: cannot open shared object file: No such file or directory

我在DIR中给出的路径转到保存共享对象的文件夹(相对于放置makefile的位置),如果路径错误,为什么在制作过程中也不会抱怨.

The path that i give in DIR goes to the folder where the shared object is held(relatively to where the makefile is placed), and if it was the wrong path why didn't it complain during the make process.

有人知道我在想什么吗?

does someone know what am i missing?

谢谢 马特

推荐答案

LDFLAGS += -L$(DIR)/lib/linux '-Wl,-R$$ORIGIN'

以上应为:

LDFLAGS += -L$(DIR)/lib/linux -Wl,-R$(DIR)/lib/linux '-Wl,-R$$ORIGIN'

即,对于每个非标准动态库位置-L,应指定一个对应的-Wl,-R.需要$ORIGIN来定位相对于可执行文件的动态库,不确定在这里是否需要它.

That is, for each non-standard dynamic library location -L a corresponding -Wl,-R should be specified. $ORIGIN is needed to locate dynamic libraries relative to the executable, not sure if you need it here.

人们经常建议使用LD_LIBRARY_PATH.我认为这是一个坏建议,因为它会使部署更加复杂.

People often advise using LD_LIBRARY_PATH. This is a bad advice, in my opinion, because it makes deployment more complicated.

这篇关于Makefile-找不到共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆