470,870 Members | 1,160 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

Compiler problem with c-code in Matlab

I have a Matlab code which works fine in windows. Now I installed Xubuntu (because this way I have admin rights(=root) which I don't have on windows) and want to use the same code.

To be able to use the C-code you have to compile it from Matlab comand line with the comand
Expand|Select|Wrap|Line Numbers
  1. mex myfile.c
where before with mex -setup you define which compiler to use, the only choice I had was gcc (version 4.something).

Now if I compile I get the following error:
Expand|Select|Wrap|Line Numbers
  1. >> mex givegradient.c
  2. Warning: You are using gcc version "4.1.2".  The earliest gcc version supported
  3. with mex is "3.4.0".  The latest version tested for use with mex is "3.4.5".
  4. To download a different version of gcc, visit http://gcc.gnu.org 
  5. givegradient.c:2: error: expected identifier or ‘(’ before ‘/’ token
  6. givegradient.c:16: error: expected identifier or ‘(’ before ‘/’ token
  7. givegradient.c:142: error: expected declaration specifiers or ‘...’ before ‘/’ token
  8. givegradient.c:143: error: expected declaration specifiers or ‘...’ before ‘/’ token
  9. givegradient.c:144: error: expected declaration specifiers or ‘...’ before ‘/’ token
  10. givegradient.c:147: error: conflicting types for ‘mexFunction’
  11. /usr/local/matlab/extern/include/mex.h:148: error: previous declaration of ‘mexFunction’ was here
  12. givegradient.c: In function ‘mexFunction’:
  13. givegradient.c:156: error: ‘nrhs’ undeclared (first use in this function)
  14. givegradient.c:156: error: (Each undeclared identifier is reported only once
  15. givegradient.c:156: error: for each function it appears in.)
  16. givegradient.c:159: error: ‘prhs’ undeclared (first use in this function)
  17. givegradient.c:159: warning: assignment discards qualifiers from pointer target type
  18. givegradient.c:166: error: ‘plhs’ undeclared (first use in this function)
  20.     mex: compile of 'givegradient.c' failed.
  22. ??? Error using ==> mex
  23. Unable to complete successfully.
And the first lines of my code have just the usual comments, i.e.:
Expand|Select|Wrap|Line Numbers
  1. /* $Revision: 1.1 $ */
  2. // Automatically generated by Matlab AppWizard version 1.0
  3. //
  4. // This is the gateway routine for a MATLAB Math/Graphics Library-based
  5. // C MATLAB MEX File.
  8. #include "mex.h"
  9. #include <math.h>
  10. #define K 10.0
  11. #define MAX(A,B) ((A)>(B)?(A):(B))
  12. #define MIN(A,B) ((A)<(B)?(A):(B))
  13. #define SGN(A) ((A)>0?1.:-1.)
  14. #define ABS(A) ((A)>0?(A):-(A))
  16. etc.
I can post also the rest of the code if needed...

I think it must be a compiler thing because the code worked with no problems on windows...
Thanks for any help
Feb 22 '08 #1
1 4329
With some help from someone at work I figures it out, in order to have it seen as a C++ file you have to name the file as *.cc or *.cpp and then it works fine....
Feb 22 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Christopher M. Lusardi | last post: by
12 posts views Thread by Unbiased_me | last post: by
1 post views Thread by Ayende Rahien | last post: by
3 posts views Thread by Mark Rockman | last post: by
12 posts views Thread by nicdude | last post: by
reply views Thread by skip | last post: by
30 posts views Thread by lovecreatesbea... | last post: by
49 posts views Thread by valentin tihomirov | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.