liuliu / ccv

C-based/Cached/Core Computer Vision Library, A Modern Computer Vision Library
http://libccv.org
Other
7.07k stars 1.71k forks source link

Could not run simplest example (Segmentation fault) #217

Closed marrrcin closed 5 years ago

marrrcin commented 5 years ago

Hi @liuliu , I'm struggling with installation of your library. I've tested it on clean VMs with:

and on each one of them result is the same - running the following code:

#include <ccv.h>

int main(int argc, char** argv)
{
        ccv_dense_matrix_t* image = 0;
        ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE);
        ccv_write(image, argv[2], 0, CCV_IO_PNG_FILE, 0);
        return 0;
}

compiled with:

clang -L"/home/m/ccv/lib" -I"/home/m/ccv/lib" test.c -lccv `cat /home/m/ccv/lib/.deps` -o test

and run:

./test img.jpg img.png

ends up with:

Segmentation fault (core dumped)

Reason is that: ccv_read(argv[1], &image, CCV_IO_GRAY | CCV_IO_ANY_FILE); results in image pointer still being 0 instead of allocated image.

So my belief is that there is a missing piece of documentation that explains how to configure something more before the compilation. I have libjpeg and libpng installed. What are the prerequisites for the installation?


FYI, my config.mk:

CC := clang
AR := ar
NVCC :=
CUDA_SRCS :=
CUDA_COMPAT_LIB :=
CUDA_CMD_LIB :=
DEFINE_MACROS := -D HAVE_LIBPNG -D HAVE_LIBJPEG -D HAVE_PTHREAD -D HAVE_UCONTEXT -D HAVE_SSE2
prefix := /usr/local
exec_prefix := ${prefix}
CFLAGS :=  -msse2 $(DEFINE_MACROS) -I${prefix}/include
NVFLAGS := --use_fast_math -arch=sm_53 $(DEFINE_MACROS)
LDFLAGS :=  -L${exec_prefix}/lib -lm -lrt -lpng -ljpeg -lpthread
liuliu commented 5 years ago

Your configuration looks right. The most important thing is: -D HAVE_LIBJPEG -D HAVE_LIBPNG macro, this tells ccv to have libjpeg / libpng code enabled. LDFLAGS looks good as well.

Are you on unstable branch? unstable branch diverged a lot due to new work in libnnc. It could be CCV_IO_GRAY code path is less tested than CCV_IO_RGB_COLOR.

It also could simply be the file img.jpeg is not accessible for the program, you can check the returned value for that (if it is CCV_IO_ERROR, it is not accessible).

Overall, I think the root cause could be you don't have access to the file (if it is indeed you compile with the said config.mk file). I checked the code again, even on unstable branch, CCV_IO_GRAY would at least allocate the image matrix for you.

Ubuntu 18.04 is a pretty standard configuration I had (the same with 16.04), the CI pipeline covers it: https://ci.libccv.org/waterfall / https://github.com/liuliu/ccv/blob/unstable/.travis.yml

marrrcin commented 5 years ago

Thanks for a quick reply! OK, so when I've installed all of the packages you have listed in .travis.yml it started to work.