caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florent Monnier <monnier.florent@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] segfault with native compilation, but not in bytecode
Date: Mon, 19 Nov 2012 22:01:06 +0100	[thread overview]
Message-ID: <CAE1DttA0JjsYVi1mj3puVU6GwkbG9dsof0v=vCnBmMijaBySuA@mail.gmail.com> (raw)

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

                 reply	other threads:[~2012-11-19 21:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE1DttA0JjsYVi1mj3puVU6GwkbG9dsof0v=vCnBmMijaBySuA@mail.gmail.com' \
    --to=monnier.florent@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).