Karnivaurus
Karnivaurus

Reputation: 24131

Linker cannot find library file with explicit path

In my makefile, I have specified a library dependency as follows:

LDFLAGS := -l/home/karnivaurus/OpenCV-3.0.0/build/lib/libopencv_core.so

all: $(DYNAMIC_NAME)

$(DYNAMIC_NAME): $(OBJS) | $(LIB_BUILD_DIR)
    @ echo LD -o $@
    $(Q)$(CXX) -shared -o $@ $(OBJS) $(LINKFLAGS) $(LDFLAGS) $(DYNAMIC_FLAGS)

Now, if I run make all, I get the following error:

/usr/bin/ld: cannot find -l/home/karnivaurus/Libraries/OpenCV-3.0.0-RC1/build/lib/libopencv_core.so

However, in the directory /home/karnivaurus/Libraries/OpenCV-3.0.0-RC1/build/lib, there is definitely a file called libopencv_core.so. I have checked the spelling many times!

Are there any reasons why the linker cannot find this file, even though I have explicitly specified its exact location and passed that to the linker?

Thanks!

Upvotes: 2

Views: 2354

Answers (1)

sehe
sehe

Reputation: 393694

Either use -L for the library path and -lopencv_core:

LDFLAGS := -L /home/karnivaurus/OpenCV-3.0.0/build/lib/ -lopencv_core

or just include the full path to the .so file without -l.

LDFLAGS := /home/karnivaurus/OpenCV-3.0.0/build/lib/libopencv_core.so

Upvotes: 4

Related Questions