# Can't build Opencv program

**URL:** <https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311>\
**Category:** Jetson TK1\
**Tags:** opencv\
**Created:** [June 10, 2015, 7:26pm UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311 "2015-06-10T19:26:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mons91](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mons91](https://forums.developer.nvidia.com/u/mons91)\
**Post date:** [June 10, 2015, 7:26pm UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/1 "2015-06-10T19:26:03Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![linuxdev](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/linuxdev/32/10243_2.png) [@linuxdev](https://forums.developer.nvidia.com/u/linuxdev)\
**Post date:** [June 10, 2015, 8:14pm UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/2 "2015-06-10T20:14:20Z")

</div>

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:

```auto
ldconfig -p

```

From that you could filter with grep:

```auto
ldconfig -p | egrep libopencv

```

To search your system for files starting with name libopencv:

```auto
sudo find / -name 'libopencv*'

```

Where is the exact file “libopencv\_core.so.2.4” at?

---

<div class="post-metadata">

**Author:** ![mons91](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mons91](https://forums.developer.nvidia.com/u/mons91)\
**Post date:** [June 10, 2015, 8:25pm UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/3 "2015-06-10T20:25:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![linuxdev](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/linuxdev/32/10243_2.png) [@linuxdev](https://forums.developer.nvidia.com/u/linuxdev)\
**Post date:** [June 10, 2015, 8:30pm UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/4 "2015-06-10T20:30:59Z")

</div>

> [@](#):
>
> 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?

---

<div class="post-metadata">

**Author:** ![mons91](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mons91](https://forums.developer.nvidia.com/u/mons91)\
**Post date:** [June 11, 2015, 7:36am UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/5 "2015-06-11T07:36:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mons91](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@mons91](https://forums.developer.nvidia.com/u/mons91)\
**Post date:** [June 11, 2015, 7:38am UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/6 "2015-06-11T07:38:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chenghaibo](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/chenghaibo/32/12530_2.png) [@Chenghaibo](https://forums.developer.nvidia.com/u/Chenghaibo)\
**Post date:** [June 17, 2015, 7:45am UTC](https://forums.developer.nvidia.com/t/cant-build-opencv-program/38311/7 "2015-06-17T07:45:59Z")

</div>

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
