Can't build Opencv program

Hi everybody!
This is gonna be probably a noob question but… when I try to build my opencv program on the Jetson Tk1 (that I tested on Ubuntu and so I’m sure it works) I receive a strange error, that is:

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

Looking over the net I found that this problem can be solved on ubuntu doing:

sudo /bin/bash -c ‘echo “/usr/local/lib” > /etc/ld.so.conf.d/opencv.conf’
sudo ldconfig

that I adapted for the jetson to:

sudo /bin/bash -c ‘echo “/usr/lib” > /etc/ld.so.conf.d/opencv.conf’
sudo ldconfig

Since Opencv shows shared library over the /usr/lib folder but…It is still not working…

Can someone help me?

Thank you very much!

Your linker path is controlled by ld, which reads and appends to searched linker path what you add to /etc/ld.so.conf.d/. Normally /usr/lib is already searched, so adding it won’t help find something there.

Your linker is specifically looking for “libopencv_core.so.2.4”. Where is it located? Is it in /usr/lib? If so, is it a hard link, or is it a symbolic link (naming convention says it’ll be a hard link)?

You can print a list of what the linker sees:

ldconfig -p

From that you could filter with grep:

ldconfig -p | egrep libopencv

To search your system for files starting with name libopencv:

sudo find / -name 'libopencv*'

Where is the exact file “libopencv_core.so.2.4” at?

it’s a softlink placed in /usr/lib that points to libopencv_core.so.2.4.10 in the same directory

Does libopencv_core.so.2.4.10 (the sym link target) exist as a hard file in /usr/lib? And what permissions does it have?

yes it is a hard file and the permissions given are: -rw-r–r–

OK I solved!!
The problem was that I was building with the flags:

-mfloat-abi=softfp -mfpu=neon

but since opencv4tegra is CPU optimized, actually it goes in conflicts and is not able anymore to be opened.

i have rewrite a make file like this, yet at first, please copy /lib , /usr/include, /usr/lib/ from tk1 board to a host folder, example
/home/rock/cuda-workspace;

the copy this make file

################################################################################

Copyright 1993-2013 NVIDIA Corporation. All rights reserved.

NOTICE TO USER:

This source code is subject to NVIDIA ownership rights under U.S. and

international Copyright laws.

NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE

CODE FOR ANY PURPOSE. IT IS PROVIDED “AS IS” WITHOUT EXPRESS OR

IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH

REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF

MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.

IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,

OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS

OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE

OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE

OR PERFORMANCE OF THIS SOURCE CODE.

U.S. Government End Users. This source code is a “commercial item” as

that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of

“commercial computer software” and "commercial computer software

documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)

and is provided to the U.S. Government only as a commercial end item.

Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through

227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the

source code with only those rights set forth herein.

################################################################################

Makefile project only supported on Mac OS X and Linux Platforms)

################################################################################

Location of the CUDA Toolkit

CUDA_PATH ?= /usr/local/cuda-6.5
TARGET_FS = /home/rock/cuda-workspace
OS_SIZE = 32
OS_ARCH = armv7l
ARCH_FLAGS = -target-cpu-arch ARM
ARMv7 = 1
dbg = 1

Common binaries

GCC ?= arm-linux-gnueabihf-g++
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(GCC)

internal flags

NVCCFLAGS := -m${OS_SIZE} ${ARCH_FLAGS}
CCFLAGS :=
LDFLAGS := -nostdlib

Extra user flags

EXTRA_NVCCFLAGS ?=
EXTRA_LDFLAGS ?=
EXTRA_CCFLAGS ?=

OS-specific build flags

override abi := gnueabihf
LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
CCFLAGS += -mfloat-abi=hard

ifeq ($(ARMv7),1)
ifneq ($(TARGET_FS),)
GCCVERSIONLTEQ46 := $(shell expr $(GCC) -dumpversion <= 4.6)
ifeq ($(GCCVERSIONLTEQ46),1)
CCFLAGS += --sysroot=$(TARGET_FS)
endif
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/lib/arm-linux-$(abi)
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-$(abi)
endif
endif

Debug build flags

ifeq ($(dbg),1)
NVCCFLAGS += -g -G
TARGET := debug
else
TARGET := release
endif

ALL_CCFLAGS :=
ALL_CCFLAGS += $(NVCCFLAGS)
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))

ALL_LDFLAGS :=
ALL_LDFLAGS += $(ALL_CCFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))

Common includes and paths for CUDA

INCLUDES := -I$(TARGET_FS)/usr/include
LIBRARIES :=

################################################################################

SAMPLE_ENABLED := 1

Makefile include to help find GL Libraries

OpenGL specific libraries

LIBRARIES += -L$(TARGET_FS)/lib
LIBRARIES += -L$(TARGET_FS)/lib/arm-linux-gnueabihf
LIBRARIES += -L$(TARGET_FS)/usr/lib
#LIBRARIES += -L$(TARGET_FS)/usr/lib/arm-linux-gnueabihf
LIBRARIES += -lc
LIBRARIES += -lcudart
LIBRARIES += -lpthread
LIBRARIES += -lopencv_highgui
LIBRARIES += -lopencv_core
LIBRARIES += -lopencv_imgproc

SMS ?= 32

ifeq ($(SMS),)
$(info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
SAMPLE_ENABLED := 0
endif

ifeq ($(GENCODE_FLAGS),)

Generate SASS code for each SM architecture listed in $(SMS)

$(foreach sm,$(SMS),$(eval GENCODE_FLAGS += -gencode arch=compute_$(sm),code=sm_$(sm)))

Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility

HIGHEST_SM := $(lastword $(sort $(SMS)))
ifneq ($(HIGHEST_SM),)
GENCODE_FLAGS += -gencode arch=compute_$(HIGHEST_SM),code=compute_$(HIGHEST_SM)
endif
endif

ifeq ($(SAMPLE_ENABLED),0)
EXEC ?= @echo “[@]”
endif

################################################################################

Target rules

all: build

build: OpenCV_one

check.deps:
ifeq ($(SAMPLE_ENABLED),0)
@echo “Sample will be waived due to the above missing dependencies”
else
@echo “Sample is ready - all dependencies have been met”
endif

OpenCV_one.o:OpenCV_one.cpp
$(EXEC) $(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<

OpenCV_one: OpenCV_one.o
$(EXEC) $(NVCC) -cudart shared $(ALL_LDFLAGS) $(GENCODE_FLAGS) -o $@ $+ $(LIBRARIES)

run: build
$(EXEC) ./OpenCV_one

clean:
rm -f *.o OpenCV_one

clobber: clean