caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] segfault with native compilation, but not in bytecode
@ 2012-11-19 21:01 Florent Monnier
  0 siblings, 0 replies; only message in thread
From: Florent Monnier @ 2012-11-19 21:01 UTC (permalink / raw)
  To: Caml List

Hi,

My program runs fine with opencv in bytecode, but
I don't succeed to run it with opencv in native code.
Here is minimal code to reproduce the error:

here is a test in C:
$ cat err_c.c
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>

int main()
{
    CvCapture *capture = cvCreateCameraCapture(0);
    if (!capture) exit(1);
    cvReleaseCapture(&capture);
    return 0;
}

$ gcc -lopencv_core -lopencv_highgui -lm err_c.c -o err_c
$ ./err_c

##OK

Now trying to do the same in ocaml, in native code:

$ cat err.ml
external test : unit -> unit = "my_cv_test"

let () = test ()

$ cat err_stub.c
#include <opencv2/core/core_c.h>
#include <opencv2/highgui/highgui_c.h>

#define CAML_NAME_SPACE
#include <caml/mlvalues.h>

CAMLprim value
my_cv_test(value unit)
{
    CvCapture *capture = cvCreateCameraCapture(0);
    if (!capture) exit(1);
    cvReleaseCapture(&capture);
    return Val_unit;
}

$ ocamlopt -o err.opt err.ml err_stub.c -cclib "-lopencv_core
-lopencv_highgui -lm"
$ ./err.opt
Segmentation fault

$ gdb ./err.opt
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0xb7da204b in cvCreateCameraCapture () from /usr/lib/libopencv_highgui.so.2.3
(gdb) bt
#0  0xb7da204b in cvCreateCameraCapture () from
/usr/lib/libopencv_highgui.so.2.3
#1  0x0804c241 in my_cv_test ()
#2  0x08049ccc in camlErr__entry ()
#3  0x08049981 in caml_program ()
#4  0x0805990a in caml_start_program ()
#5  0x08059dad in caml_main ()
#6  0x0804c280 in main ()

There is no initialisation function that has to be called before this
function, as you can see with this example sample:
https://github.com/Itseez/opencv/blob/master/samples/c/fback_c.c

I do NOT get this segfault in bytecode mode, and my program runs fine.
It only segfaults in native code.

What could be wrong?
In case you don't know, would you have any advice how to search the
origine of the problem?

-- 
Cheers
Florent

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-11-19 21:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-19 21:01 [Caml-list] segfault with native compilation, but not in bytecode Florent Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).