Discussion:
Compiling .c code using mkoctfile
Colin Kikuchi
2018-12-05 23:27:34 UTC
Permalink
Hello,
I am trying to use mkoctfile to compile some .c source code. When I try to
do this, this message appears:

C:\Octave\OCTAVE~1.1\include\octave-4.4.1\octave/Array.h:30:10: fatal
error: cassert: No such file or directory
#include <cassert>

I read some of the Octave support groups and it seems that this is because
I can't #include Octave headers in the source code. It isn't clear to me if
there is a good work around. Has anyone encountered this and worked out a
fix for how to easily compile .c code using mkoctfile?

Thank you!

-Colin
Carlo De Falco
2018-12-06 06:18:05 UTC
Permalink
Hi,
Post by Colin Kikuchi
Hello,
C:\Octave\OCTAVE~1.1\include\octave-4.4.1\octave/Array.h:30:10: fatal error: cassert: No such file or directory
#include <cassert>
This #include statement is meant for C++ not C.
Post by Colin Kikuchi
I read some of the Octave support groups and it seems that this is because I can't #include Octave headers in the source code. It isn't clear to me if there is a good work around. Has anyone encountered this and worked out a fix for how to easily compile .c code using mkoctfile?
Octave libraries are in C++, not C, so you cannot include their headers in your C code and compile with a C compiler.
Depending on what you want to do, you can either

* compile your C code with a C++ compiler (the easiest way to do so is to rename it to .cc instead of .c)

* access Octave libraries via the mex interface (which is a Matlab compatible C API) as explained here : https://octave.org/doc/interpreter/Mex_002dFiles.html#Mex_002dFiles
Post by Colin Kikuchi
Thank you!
-Colin
Hope this helps, if you need more in-depth help you should provide more info, or share the .c code you are trying to compile.

c.
Colin Kikuchi
2018-12-06 16:57:44 UTC
Permalink
Hey Carlo,
Thank you for your response! I tried compiling to an mex file based on the
link you sent, using "mkoctfile --mex mexADIconf.c", but got the same
error. I am attaching an example of the code I am trying to compile (there
are several other programs like this one) in hopes that you or someone else
might be able to give me a tip about compiling into an octfile. Sorry, I am
a bit inexperienced with Octave so would really appreciate any suggestions
you might have!

Thanks again!

-Colin
Post by Colin Kikuchi
Hi,
Post by Colin Kikuchi
Hello,
I am trying to use mkoctfile to compile some .c source code. When I try
C:\Octave\OCTAVE~1.1\include\octave-4.4.1\octave/Array.h:30:10: fatal
error: cassert: No such file or directory
Post by Colin Kikuchi
#include <cassert>
This #include statement is meant for C++ not C.
Post by Colin Kikuchi
I read some of the Octave support groups and it seems that this is
because I can't #include Octave headers in the source code. It isn't clear
to me if there is a good work around. Has anyone encountered this and
worked out a fix for how to easily compile .c code using mkoctfile?
Octave libraries are in C++, not C, so you cannot include their headers in
your C code and compile with a C compiler.
Depending on what you want to do, you can either
* compile your C code with a C++ compiler (the easiest way to do so is to
rename it to .cc instead of .c)
* access Octave libraries via the mex interface (which is a Matlab
https://octave.org/doc/interpreter/Mex_002dFiles.html#Mex_002dFiles
Post by Colin Kikuchi
Thank you!
-Colin
Hope this helps, if you need more in-depth help you should provide more
info, or share the .c code you are trying to compile.
c.
Carlo De Falco
2018-12-06 17:24:46 UTC
Permalink
Post by Colin Kikuchi
Hey Carlo,
Thank you for your response! I tried compiling to an mex file based on the link you sent, using "mkoctfile --mex mexADIconf.c", but got the same error. I am attaching an example of the code I am trying to compile (there are several other programs like this one) in hopes that you or someone else might be able to give me a tip about compiling into an octfile. Sorry, I am a bit inexperienced with Octave so would really appreciate any suggestions you might have!
Thanks again!
-Colin
Compiling your code I see the following :

$ mkoctfile -mex mexADIconf.c
mexADIconf.c:37:10: warning: non-portable path to file '<Matrix.h>'; specified path differs in case from file name on disk
[-Wnonportable-include-path]
#include <matrix.h>
^~~~~~~~~~
<Matrix.h>
In file included from mexADIconf.c:37:
In file included from /opt/octave/4.4.0/include/octave-4.4.0/octave/matrix.h:31:
In file included from /opt/octave/4.4.0/include/octave-4.4.0/octave/mx-base.h:30:
In file included from /opt/octave/4.4.0/include/octave-4.4.0/octave/MatrixType.h:29:
In file included from /opt/octave/4.4.0/include/octave-4.4.0/octave/MSparse.h:29:
In file included from /opt/octave/4.4.0/include/octave-4.4.0/octave/Array-util.h:28:
/opt/octave/4.4.0/include/octave-4.4.0/octave/Array.h:30:10: fatal error: 'cassert' file not found
#include <cassert>
^~~~~~~~~
1 warning and 1 error generated.


The first message is just a warning as on macos files are not case sensitive the same would be an error on Linux.
The second one is because you are including directly matrix.h from liboctave which includes cassert which is C++.

Just comment out the unnecessary includes and all should work:

/* header */
#include <mex.h>
//#include <matrix.h>
//#include <stdlib.h>
//#include <math.h>


HTH,
c.
Colin Kikuchi
2018-12-07 03:04:26 UTC
Permalink
Hey Carlo,

Thanks, this is very helpful!
Sorry to keep bugging you, but as a follow-up question, I have tried
compiling with mkoctfile after commneting out the header information. Now,
Octave is saying that 'mwSize' is an unknown type name:

mexADIconf.c:44:14: error: unknown type name 'mwSize'
mwSize nz, mwSize nr, mwSize nper, mwSize *nt, double *dt,

My understanding is that mwSize is a type name defining the size of arrays.
Is there something I have to add to get Octave to recognize this, or should
I call it something else?

Thanks again!

-Colin
Post by Colin Kikuchi
Post by Colin Kikuchi
Hey Carlo,
Thank you for your response! I tried compiling to an mex file based on
the link you sent, using "mkoctfile --mex mexADIconf.c", but got the same
error. I am attaching an example of the code I am trying to compile (there
are several other programs like this one) in hopes that you or someone else
might be able to give me a tip about compiling into an octfile. Sorry, I am
a bit inexperienced with Octave so would really appreciate any suggestions
you might have!
Post by Colin Kikuchi
Thanks again!
-Colin
$ mkoctfile -mex mexADIconf.c
mexADIconf.c:37:10: warning: non-portable path to file '<Matrix.h>';
specified path differs in case from file name on disk
[-Wnonportable-include-path]
#include <matrix.h>
^~~~~~~~~~
<Matrix.h>
In file included from
In file included from
In file included from
In file included from
In file included from
'cassert' file not found
#include <cassert>
^~~~~~~~~
1 warning and 1 error generated.
The first message is just a warning as on macos files are not case
sensitive the same would be an error on Linux.
The second one is because you are including directly matrix.h from
liboctave which includes cassert which is C++.
/* header */
#include <mex.h>
//#include <matrix.h>
//#include <stdlib.h>
//#include <math.h>
HTH,
c.
Carlo de Falco
2018-12-07 03:22:50 UTC
Permalink
Post by Colin Kikuchi
Hey Carlo,
Thanks, this is very helpful!
Sorry to keep bugging you, but as a follow-up question, I have tried
compiling with mkoctfile after commneting out the header information. Now,
mexADIconf.c:44:14: error: unknown type name 'mwSize'
mwSize nz, mwSize nr, mwSize nper, mwSize *nt, double *dt,
My understanding is that mwSize is a type name defining the size of
arrays. Is there something I have to add to get Octave to recognize this,
or should I call it something else?
Thanks again!
-Colin
Hi,

In my previous mail I wrote which headers you would need to comment

Did you follow the hint or just comment out everything?

I see the file you sent is part of some package developed at University of
Ghent, does the package have its own makefile or some other form of
automated build?

Are you a developer of maxsym trying to port to Octave or a user trying to
install it for yourself? In the latter case did you try to contact the
developers?

c.

Loading...