Problems with mkoctfile using GCC 4.8.1

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with mkoctfile using GCC 4.8.1

Terry Duell
Hello All,
Running Octave 3.6.4 on Fedora 19 x86_64.

Trying to build a mex file, as follows;
"mkoctfile --mex apply_blur_kernel_mex.cpp" gives the following (partial)  
error message...

/usr/include/c++/4.8.1/cstdlib: In function ‘long long int std::abs(long  
long int)’:
/usr/include/c++/4.8.1/cstdlib:174:20: error: declaration of C function  
‘long long int std::abs(long long int)’ conflicts with
    abs(long long __x) { return __builtin_llabs (__x); }

A response posted to a similar error message (not related to Octave) was...

"That because header cstdlib is included in a 'extern "C"' block that gcc
4.8 doesn't support. Fix it by move the header file out of the 'extern "C"'
block."

A look at /usr/include/octave-3.6.4/octave/mexproto.h, shows...

#if defined (__cplusplus)
#include <cstdlib>
extern "C" {
#else
#include <stdlib.h>
#endif

I'm not sufficiently au fait with C and C++ to fully understand what is  
going on here.
Does anyone know if this Is this the problem, and what is the recommended  
way I fix this?

Cheers,
--
Regards,
Terry Duell
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Problems with mkoctfile using GCC 4.8.1

Terry Duell
Hello All,
A result, see below.

On Mon, 07 Oct 2013 11:03:10 +1100, Terry Duell <[hidden email]>  
wrote:

> Hello All,
> Running Octave 3.6.4 on Fedora 19 x86_64.
>
> Trying to build a mex file, as follows;
> "mkoctfile --mex apply_blur_kernel_mex.cpp" gives the following  
> (partial) error message...
>
> /usr/include/c++/4.8.1/cstdlib: In function ‘long long int std::abs(long  
> long int)’:
> /usr/include/c++/4.8.1/cstdlib:174:20: error: declaration of C function  
> ‘long long int std::abs(long long int)’ conflicts with
>     abs(long long __x) { return __builtin_llabs (__x); }
>
> A response posted to a similar error message (not related to Octave)  
> was...
>
> "That because header cstdlib is included in a 'extern "C"' block that gcc
> 4.8 doesn't support. Fix it by move the header file out of the 'extern  
> "C"'
> block."
>
> A look at /usr/include/octave-3.6.4/octave/mexproto.h, shows...
>
> #if defined (__cplusplus)
> #include <cstdlib>
> extern "C" {
> #else
> #include <stdlib.h>
> #endif
>
> I'm not sufficiently au fait with C and C++ to fully understand what is  
> going on here.
> Does anyone know if this Is this the problem, and what is the  
> recommended way I fix this?

I finally tracked down a bug report, from a little while ago, relating to  
this problem.
The fix is to move the code ' #include "mexproto.h" ' in  
'/usr/include/octave-3.6.4/octave/mex.h' (the location in Octave 3.6.4  
Fedora 19 x86_64) up about 8 lines to just prior to 'extern "C" {'.
When this done the mex file builds OK.

Cheers,
--
Regards,
Terry Duell
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

More - Problems with mkoctfile using GCC 4.8.1

Terry Duell
On Tue, 08 Oct 2013 11:20:04 +1100, Terry Duell <[hidden email]>  
wrote:

> Hello All,
> A result, see below.
>
> On Mon, 07 Oct 2013 11:03:10 +1100, Terry Duell <[hidden email]>  
> wrote:
>
>> Hello All,
>> Running Octave 3.6.4 on Fedora 19 x86_64.
>>
>> Trying to build a mex file, as follows;
>> "mkoctfile --mex apply_blur_kernel_mex.cpp" gives the following  
>> (partial) error message...
>>
>> /usr/include/c++/4.8.1/cstdlib: In function ‘long long int  
>> std::abs(long long int)’:
>> /usr/include/c++/4.8.1/cstdlib:174:20: error: declaration of C function  
>> ‘long long int std::abs(long long int)’ conflicts with
>>     abs(long long __x) { return __builtin_llabs (__x); }
>>
>> A response posted to a similar error message (not related to Octave)  
>> was...
>>
>> "That because header cstdlib is included in a 'extern "C"' block that  
>> gcc
>> 4.8 doesn't support. Fix it by move the header file out of the 'extern  
>> "C"'
>> block."
>>
>> A look at /usr/include/octave-3.6.4/octave/mexproto.h, shows...
>>
>> #if defined (__cplusplus)
>> #include <cstdlib>
>> extern "C" {
>> #else
>> #include <stdlib.h>
>> #endif
>>
>> I'm not sufficiently au fait with C and C++ to fully understand what is  
>> going on here.
>> Does anyone know if this Is this the problem, and what is the  
>> recommended way I fix this?
>
> I finally tracked down a bug report, from a little while ago, relating  
> to this problem.
> The fix is to move the code ' #include "mexproto.h" ' in  
> '/usr/include/octave-3.6.4/octave/mex.h' (the location in Octave 3.6.4  
> Fedora 19 x86_64) up about 8 lines to just prior to 'extern "C" {'.
> When this done the mex file builds OK.
>

This isn't sorted after all.
Having successfully built mex files from cpp source using the above fix, I  
thought all was OK, but not so.
Attempting to build mex from fred.c leads to errors. If the fix for cpp in  
mex.h is reversed, fred.c builds OK.

Can this be fixed so that both .c and .cpp source can be used?

Cheers,
--
Regards,
Terry Duell
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: More - Problems with mkoctfile using GCC 4.8.1

Mike Miller
On Thu, Oct 10, 2013 at 13:22:10 +1100, Terry Duell wrote:
> Having successfully built mex files from cpp source using the above fix, I
> thought all was OK, but not so.
> Attempting to build mex from fred.c leads to errors. If the fix for cpp in
> mex.h is reversed, fred.c builds OK.
>
> Can this be fixed so that both .c and .cpp source can be used?

I don't get any errors with the example from the manual with either a
.c, .cc, or .cpp extension. You'll have to give some more information.
What is fred.c and what specific errors do you get?

--
mike
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: More - Problems with mkoctfile using GCC 4.8.1

Terry Duell
Hello Mike,

On Fri, 11 Oct 2013 08:54:35 +1100, Mike Miller <[hidden email]> wrote:

> Hi Terry, did you mean to reply off-list or forget to reply-all?

Yes, I forgot to reply-all, sorry.

>
> On Fri, Oct 11, 2013 at 08:24:43 +1100, Terry Duell wrote:
>> Fred.c was just a name as an example.
>> I don't have the specific error messages, but I recall they related to
>> mxDOUBLE.
>> I have just tried to reproduce the problem, but can't.
>> I'll have to go back and carefully check the situation again with .cpp  
>> and
>> .c sources.
>
> Ok, what I was getting at was if you have a specific example file that
> shows the error, because any example I created doesn't give me an
> error.
>
>> Are you using Octave 3.6.4?
>
> I tried with 3.6.4 (with the mexproto include moved as you noted) and
> with the current development version, both worked with no error. I
> don't work with mex files routinely, I just tried to see if I could
> reproduce your error.
>

OK, I don't normally work with mex files either, but have been revisiting  
some code I worked with a couple of years ago, Matlab code provided by  
others, and didn't have any problems compiling the xxx.c or the xxx.cpp  
files at that time. Trying to rebuild working code from my source archive,  
I now run into problems.
Below is a bit of a story of what I have been able to establish, hope it  
is understandable.

using mex.h as follows...

------------------
#if defined (__cplusplus)
#include "mexproto.h"  /*TLD 8-10-2013*/
extern "C" {
#endif

#if defined (V4)
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, mxArray *prhs[]);
#else
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray  
*prhs[]);
#endif

/*#include "mexproto.h"*/

/* V4 floating point routines renamed in V5.  */
-----------------

errors compiling apply_blur_kernel_mex.c, but no errors compiling another  
version (apply_blur_kernel_mex.cpp in different set of code)

apply_blur_kernel_mex.c:87:62: error: ‘mxDOUBLE_CLASS’ undeclared (first  
use in this function)
      imblurry_ptr = mxCreateNumericArray(3, full_dims_blurry,  
mxDOUBLE_CLASS, mxREAL);
                                                               ^
apply_blur_kernel_mex.c:87:62: note: each undeclared identifier is  
reported only once for each function it appears in
apply_blur_kernel_mex.c:87:78: error: ‘mxREAL’ undeclared (first use in  
this function)
      imblurry_ptr = mxCreateNumericArray(3, full_dims_blurry,  
mxDOUBLE_CLASS, mxREAL);
                                                                               ^
apply_blur_kernel_mex.c:88:14: warning: assignment makes pointer from  
integer without a cast [enabled by default]
      imblurry = mxGetPr(imblurry_ptr);
               ^
apply_blur_kernel_mex.c:95:16: warning: implicit declaration of function  
‘mexErrMsgTxt’ [-Wimplicit-function-declaration]
                 mexErrMsgTxt("theta not integral for uniform blur");
                 ^
apply_blur_kernel_mex.c:107:22: error: ‘mwIndex’ undeclared (first use in  
this function)
                  i = (mwIndex)((xi-1)*h_blurry + yi - 1);
                       ^

with mex.h as follows (essentially the std mex.h in 3.6.4), no errors  
compiling apply_blur_kernel_mex.c but errors (in original post) compiling  
apply_blur_kernel_mex.cpp

-------------------
#if defined (__cplusplus)
/* #include "mexproto.h"  TLD 8-10-2013*/
extern "C" {
#endif

#if defined (V4)
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, mxArray *prhs[]);
#else
void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray  
*prhs[]);
#endif

#include "mexproto.h"

/* V4 floating point routines renamed in V5.  */
----------------------

Just to be clear, I am working with Octave 3.6.4 from the Fedora 19 repo  
(x86_64 version).
Fedora 19 uses gcc-4.8.1-1.fc19.x86_64.

What version of GCC are you using.

Hope this throws a bit more light on my problem.

Cheers,
--
Regards,
Terry Duell
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: More - Problems with mkoctfile using GCC 4.8.1

Mike Miller
On Fri, Oct 11, 2013 at 14:54:45 +1100, Terry Duell wrote:

> OK, I don't normally work with mex files either, but have been
> revisiting some code I worked with a couple of years ago, Matlab
> code provided by others, and didn't have any problems compiling the
> xxx.c or the xxx.cpp files at that time. Trying to rebuild working
> code from my source archive, I now run into problems.
> Below is a bit of a story of what I have been able to establish,
> hope it is understandable.
>
> using mex.h as follows...
>
> ------------------
> #if defined (__cplusplus)
> #include "mexproto.h"  /*TLD 8-10-2013*/
> extern "C" {
> #endif
>
> #if defined (V4)
> void mexFunction (int nlhs, mxArray* plhs[], int nrhs, mxArray *prhs[]);
> #else
> void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray
> *prhs[]);
> #endif
>
> /*#include "mexproto.h"*/
>
> /* V4 floating point routines renamed in V5.  */
> -----------------
>
> errors compiling apply_blur_kernel_mex.c, but no errors compiling
> another version (apply_blur_kernel_mex.cpp in different set of code)
>
> apply_blur_kernel_mex.c:87:62: error: ‘mxDOUBLE_CLASS’ undeclared
> (first use in this function)
>      imblurry_ptr = mxCreateNumericArray(3, full_dims_blurry,
> mxDOUBLE_CLASS, mxREAL);
>                                                               ^
> apply_blur_kernel_mex.c:87:62: note: each undeclared identifier is
> reported only once for each function it appears in
> apply_blur_kernel_mex.c:87:78: error: ‘mxREAL’ undeclared (first use
> in this function)
>      imblurry_ptr = mxCreateNumericArray(3, full_dims_blurry,
> mxDOUBLE_CLASS, mxREAL);
>                                                                               ^
> apply_blur_kernel_mex.c:88:14: warning: assignment makes pointer
> from integer without a cast [enabled by default]
>      imblurry = mxGetPr(imblurry_ptr);
>               ^
> apply_blur_kernel_mex.c:95:16: warning: implicit declaration of
> function ‘mexErrMsgTxt’ [-Wimplicit-function-declaration]
>                 mexErrMsgTxt("theta not integral for uniform blur");
>                 ^
> apply_blur_kernel_mex.c:107:22: error: ‘mwIndex’ undeclared (first
> use in this function)
>                  i = (mwIndex)((xi-1)*h_blurry + yi - 1);
>                       ^
>
> with mex.h as follows (essentially the std mex.h in 3.6.4), no
> errors compiling apply_blur_kernel_mex.c but errors (in original
> post) compiling apply_blur_kernel_mex.cpp
>
> -------------------
> #if defined (__cplusplus)
> /* #include "mexproto.h"  TLD 8-10-2013*/
> extern "C" {
> #endif
>
> #if defined (V4)
> void mexFunction (int nlhs, mxArray* plhs[], int nrhs, mxArray *prhs[]);
> #else
> void mexFunction (int nlhs, mxArray* plhs[], int nrhs, const mxArray
> *prhs[]);
> #endif
>
> #include "mexproto.h"
>
> /* V4 floating point routines renamed in V5.  */
> ----------------------
>
> Just to be clear, I am working with Octave 3.6.4 from the Fedora 19
> repo (x86_64 version).
> Fedora 19 uses gcc-4.8.1-1.fc19.x86_64.
>
> What version of GCC are you using.
>
> Hope this throws a bit more light on my problem.

Yes it does. The edit you made to mex.h was slightly off, compare the
current development version to see where the change should actually be
made:

  http://hg.savannah.gnu.org/hgweb/octave/file/811019b9ef57/libinterp/corefcn/mex.h#l67

Specifically the mexproto.h file should be included outside of the #if
block, that is why it's not working for C files for you. Try adjusting
that and let us know if it works for you.

I'm using gcc version 4.8.1 (Debian 4.8.1-10).

--
mike
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: More - Problems with mkoctfile using GCC 4.8.1

Terry Duell
On Fri, 11 Oct 2013 22:56:20 +1100, Mike Miller <[hidden email]> wrote:

> On Fri, Oct 11, 2013 at 14:54:45 +1100, Terry Duell wrote:

[snip]

>>
>> Hope this throws a bit more light on my problem.
>
> Yes it does. The edit you made to mex.h was slightly off, compare the
> current development version to see where the change should actually be
> made:
>
>   http://hg.savannah.gnu.org/hgweb/octave/file/811019b9ef57/libinterp/corefcn/mex.h#l67
>
> Specifically the mexproto.h file should be included outside of the #if
> block, that is why it's not working for C files for you. Try adjusting
> that and let us know if it works for you.

Aaah, I should have spotted that. A silly/simple oversight.
I can now compile the c and cpp sources without error.

Many thanks for your help.

Cheers,
--
Regards,
Terry Duell
_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave