help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: C program and mkoctfile problem


From: Kai Torben Ohlhus
Subject: Fwd: C program and mkoctfile problem
Date: Tue, 21 May 2019 09:39:24 +0200

On Tue, May 21, 2019 at 9:10 AM Marco Cecconello <address@hidden> wrote:
Dear Kia,
yes, not sure what happened. Below the original text.

Thanks
Marco

Why is the following not working?

C code: simple.c

// Inclusion of standard header files
#include <stdio.h>

int main (void)
{
        int a, b, c;
        a = 4;
        b = 3;
        c = a + b;

        printf("Result is %d\n", c);

        return c;
}


C++ wrapper: simple_wrap.cpp


#include <octave/oct.h>
extern "C" int simple (void);

DEFUN_DLD (simple, args, nargout, "simple test")
{
  int nargin = args.length ();

  octave_value_list retval;

  octave_stdout << "simple test "
                << nargin << " input arguments and "
                << nargout << " output arguments.\n";
  simple();
  retval(0) = 1;
  return retval;
}


Then:

octave:32> mkoctfile simple_wrap.cpp simple.c
octave:33> simple
error: 'simple' undefined near line 1 column 1


Please keep the mailing list in the cc, so others may benefit from our discussion.

Your file "simple.c" should not define a "main", but a "simple" function:

#include <stdio.h>

int simple (void)
{
        int a, b, c;
        a = 4;
        b = 3;
        c = a + b;

        printf("Result is %d\n", c);

        return c;
}

Then compile with "mkoctfile -o simple.oct simple_wrap.cpp simple.c", to create "simple.oct" instead of "simple_wrap.oct".

HTH,
Kai

reply via email to

[Prev in Thread] Current Thread [Next in Thread]