Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling make_mex in MATLAB 2012b #3

Open
skinney75 opened this issue Oct 1, 2012 · 17 comments
Open

Compiling make_mex in MATLAB 2012b #3

skinney75 opened this issue Oct 1, 2012 · 17 comments

Comments

@skinney75
Copy link

Hi,

I wonder if you can help with an issue that I am seeing, I am running MATLAB on a Windows 7 machine and I would like to compile your julia-matlab code.

I have ZeroMQ installed and I am using the 32-bit version of MATLAB which has its own compiler, however when I do 'make_mex' as instructed I get the following:

make_mex
Error zmq_connect.c: .\zmq.h: 71 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 126 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 129 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 144 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 145 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 146 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 147 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 150 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 151 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 162 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 163 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 164 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 166 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 167 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 168 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 169 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 170 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 171 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 172 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 173 unrecognized declaration
Error zmq_connect.c: .\zmq.h: 174 too many errors

C:\PROGRA~2\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'zmq_connect.c' failed.

It seems that each declaration that has the ZMQ_EXPORT definition raises an error, for example on line 71 is the definition:

ZMQ_EXPORT void zmq_version(int *major, int *minor, int *patch)

Do you know how I can resolve this issue?

Thanks in advance,

Chris

@timholy
Copy link
Member

timholy commented Oct 1, 2012

Unfortunately, his looks like a problem in ZeroMQ, not in my code. Can you successfully compile and run their own (C-based) demo programs?

What version of ZeroMQ are you using?

@skinney75
Copy link
Author

Hi,

I am using ZeroMQ 3.2.0.

I have not used ZeroMQ, which is the best demo to try to compile?

Thanks,

Chris


From: Tim Holy [mailto:[email protected]]
Sent: 01 October 2012 15:11
To: timholy/julia-matlab
Cc: SKINNER Christian
Subject: Re: [julia-matlab] Compiling make_mex in MATLAB 2012b (#3)

Unfortunately, his looks like a problem in ZeroMQ, not in my code. Can you successfully compile and run their own (C-based) demo programs?

What version of ZeroMQ are you using?

Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-9033168.

@timholy
Copy link
Member

timholy commented Oct 1, 2012

On Monday, October 01, 2012 07:28:47 AM skinney75 wrote:

Hi,

I am using ZeroMQ 3.2.0.

3.2 is far too buggy to use now (I think I even mention that in the Readme).
The 2.x series is strongly recommended.

I have not used ZeroMQ, which is the best demo to try to compile?

I bet switching to 2.x will fix it, but maybe this one?

https://github.com/imatix/zguide/blob/master/examples/C/hwserver.c

It may compile even under 3.2, of course, since it's one of their main demo
programs. But even when you can get 3.2 to compile, I've found it's very bug-
ridden.

Best,
--Tim

@skinney75
Copy link
Author

Hi,

I have installed ZeroMQ 2.2 and I have the same issue.

I will try to compile the sample you suggest.

Regards,

Chris

@skinney75
Copy link
Author

Hi Tim,

I have downloaded the Windows 7 SDK which had some additional compilers and I have tried the 'make_mex' again.

I still get errors but they are now in zmq_connect.c:

make_mex
zmq_connect.c
zmq_connect.c(23) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(31) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(32) : error C2065: 'urlstr' : undeclared identifier
zmq_connect.c(32) : warning C4047: '==' : 'int' differs in levels of indirection from 'void '
zmq_connect.c(36) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(41) : error C2065: 'sockettype' : undeclared identifier
zmq_connect.c(45) : error C2275: 'mxClassID' : illegal use of this type as an expression
c:\program files (x86)\matlab\r2012b\extern\include\matrix.h(353) : see declaration of 'mxClassID'
zmq_connect.c(45) : error C2146: syntax error : missing ';' before identifier 'classid'
zmq_connect.c(45) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(47) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(49) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(51) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(52) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(55) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(56) : error C2065: 'ctx' : undeclared identifier
zmq_connect.c(56) : warning C4047: '==' : 'int' differs in levels of indirection from 'void *'
zmq_connect.c(59) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(63) : error C2065: 'urlstr' : undeclared identifier
zmq_connect.c(63) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
zmq_connect.c(63) : warning C4024: 'zmq_connect' : different types for formal and actual parameter 2
zmq_connect.c(66) : error C2065: 'urlstr' : undeclared identifier
zmq_connect.c(66) : warning C4022: 'mxFree' : pointer mismatch for actual parameter 1
zmq_connect.c(69) : error C2143: syntax error : missing ';' before 'type'
zmq_connect.c(70) : error C2065: 'ptr' : undeclared identifier
zmq_connect.c(70) : error C2100: illegal indirection
zmq_connect.c(70) : error C2065: 'ctx' : undeclared identifier
zmq_connect.c(71) : error C2065: 'ptr' : undeclared identifier
zmq_connect.c(71) : warning C4047: '=' : 'int' differs in levels of indirection from 'void *
'
zmq_connect.c(72) : error C2065: 'ptr' : undeclared identifier
zmq_connect.c(72) : error C2100: illegal indirection
zmq_connect.c(72) : warning C4047: '=' : 'int' differs in levels of indirection from 'SOCKET (__stdcall *)(int,int,int)'

C:\PROGRA~2\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'zmq_connect.c' failed.

It looks like it is failing on MATLAB calls, can I ask what version of MATLAB you are using?

Regards,

Chris

@timholy
Copy link
Member

timholy commented Oct 2, 2012

I still get errors but they are now in zmq_connect.c:
[snip]
It looks like it is failing on MATLAB calls, can I ask what version of MATLAB you are using?

I've used a couple (current R2012a), but I think the problem is that your C compiler doesn't like to have the variable declarations on the same line as assignment. I've changed the code, please try again (and sorry for the inconvenience).

@skinney75
Copy link
Author

Thanks I will get the new code.

Out of interest are you using MATLAB 64 or 32 bit?


From: Tim Holy [mailto:[email protected]]
Sent: 02 October 2012 19:49
To: timholy/julia-matlab
Cc: SKINNER Christian
Subject: Re: [julia-matlab] Compiling make_mex in MATLAB 2012b (#3)

I still get errors but they are now in zmq_connect.c:
[snip]
It looks like it is failing on MATLAB calls, can I ask what version of MATLAB you are using?

I've used a couple (current R2012a), but I think the problem is that your C compiler doesn't like to have the variable declarations on the same line as assignment. I've changed the code, please try again (and sorry for the inconvenience).

Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-9082218.

@skinney75
Copy link
Author

Hi,

I have tried the new code and most of the errors have gone, there seems to be one left relating to the definition of classid:

make_mex
zmq_connect.c
zmq_connect.c(48) : error C2275: 'mxClassID' : illegal use of this type as an expression
c:\program files (x86)\matlab\r2012b\extern\include\matrix.h(353) : see declaration of 'mxClassID'
zmq_connect.c(48) : error C2146: syntax error : missing ';' before identifier 'classid'
zmq_connect.c(48) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(50) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(52) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(54) : error C2065: 'classid' : undeclared identifier
zmq_connect.c(55) : error C2065: 'classid' : undeclared identifier

C:\PROGRA~2\MATLAB\R2012B\BIN\MEX.PL: Error: Compile of 'zmq_connect.c' failed.


From: Tim Holy [mailto:[email protected]]
Sent: 02 October 2012 19:49
To: timholy/julia-matlab
Cc: SKINNER Christian
Subject: Re: [julia-matlab] Compiling make_mex in MATLAB 2012b (#3)

I still get errors but they are now in zmq_connect.c:
[snip]
It looks like it is failing on MATLAB calls, can I ask what version of MATLAB you are using?

I've used a couple (current R2012a), but I think the problem is that your C compiler doesn't like to have the variable declarations on the same line as assignment. I've changed the code, please try again (and sorry for the inconvenience).

Reply to this email directly or view it on GitHubhttps://github.com//issues/3#issuecomment-9082218.

@timholy
Copy link
Member

timholy commented Oct 3, 2012

On Wednesday, October 03, 2012 12:43:13 AM skinney75 wrote:

Thanks I will get the new code.

Out of interest are you using MATLAB 64 or 32 bit?

64


From: Tim Holy [mailto:[email protected]]
Sent: 02 October 2012 19:49
To: timholy/julia-matlab
Cc: SKINNER Christian
Subject: Re: [julia-matlab] Compiling make_mex in MATLAB 2012b (#3)

I still get errors but they are now in zmq_connect.c:
[snip]
It looks like it is failing on MATLAB calls, can I ask what version of
MATLAB you are using?

I've used a couple (current R2012a), but I think the problem is that your C
compiler doesn't like to have the variable declarations on the same line as
assignment. I've changed the code, please try again (and sorry for the
inconvenience).

Reply to this email directly or view it on
GitHub<#3 (comment)
8>.


Reply to this email directly or view it on GitHub:
#3 (comment)

@skinney75
Copy link
Author

Thanks Tim,

I think our posts got slightly mixed up, did you see my response to trying your new code this morning?

@skinney75
Copy link
Author

Hi Tim,

I changed my copy of the zmq_connect.c to have the 'class id' with the other variables that you changed recently. I now get on to the link stage and get:

Warning: MEX could not find the library "zmq" specified with -l option.
MEX looked for a file with one of the names:
zmq.lib
libzmq.lib
MEX looked for the library in the following directories:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB
C:\Program Files\Microsoft SDKs\Windows\v7.1\LIB
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\LIB
C:\Program Files (x86)\MATLAB\R2012b\extern\lib\win32
C:\Program Files (x86)\MATLAB\R2012b\extern\lib\win32\microsoft

Creating library C:\Users\Admin\AppData\Local\Temp\mex_ep8dWE\templib.x and object C:\Users\Admin\AppData\Local\Temp\mex_ep8dWE\templib.exp
zmq_connect.obj : error LNK2019: unresolved external symbol __imp__zmq_connect referenced in function _mexFunction
zmq_connect.obj : error LNK2019: unresolved external symbol __imp__zmq_socket referenced in function _mexFunction
zmq_connect.obj : error LNK2019: unresolved external symbol __imp__zmq_strerror referenced in function _mexFunction
zmq_connect.obj : error LNK2019: unresolved external symbol __imp__zmq_errno referenced in function _mexFunction
zmq_connect.obj : error LNK2019: unresolved external symbol __imp__zmq_init referenced in function _mexFunction
zmq_connect.mexw32 : fatal error LNK1120: 5 unresolved externals

C:\PROGRA~2\MATLAB\R2012B\BIN\MEX.PL: Error: Link of 'zmq_connect.mexw32' failed.

C:\Program Files (x86)\ZeroMQ 2.2.0\lib has:

libzmq-v100-mt.lib and libzmq-v100-mt-gd.lib I cant seem to find zmq.lib, am I missing something or do I need to change the 'make_mex' file?

@timholy
Copy link
Member

timholy commented Oct 5, 2012

Hmm, this is weird: I sent two emails saying I had fixed this one, too (see commit from two days ago), but somehow they never appeared here.

But obviously there are still problems. Unfortunately, I know nothing about linking on Windows. I would definitely consider changing the mex file. If you find some general solution, please submit a pull request and I'll merge it. Alternatively, under Linux I might think about making a link to the library in one of the places it's expecting to find it. (But I really don't know my way around Windows at all, so don't take this suggestion too seriously.)

Sorry this is such trouble. Compiling MEX files is a pain---part of the point of this package, of course!

@aeronmiles
Copy link

Hi thank you kindly for contributing this code... I have been getting this issue when trying to compile:

"zmq_connect.c(2) : fatal error C1083: Cannot open include file: 'zmq.h': No such file or directory

C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Compile of 'zmq_connect.c' failed. "

Is there any solutions?

many thanks

@timholy
Copy link
Member

timholy commented Feb 20, 2013

This means that zmq.h is not on your include search path. I don't know Windows, unfortunately, and I don't have a system I could easily test on. So I don't know how one goes about fixing this. How did you install ZeroMQ?

@prdubois
Copy link

prdubois commented Sep 9, 2014

It took some work but I managed to compile the MEX files under Windows.

I'm using:

  • Matlab R2014a 64 bits
  • Microsoft Windows SDK 7.1 as the free compiler
  • ZeroMQ 4.0.4, 64 bits

First, the make_mex.m needs to be changed as follows (got that hint from another ZeroMQ/Matlab project: https://github.com/smcgill3/zeromq-matlab):
mex zmq_connect.c -I"C:\Program Files\ZeroMQ 4.0.4\include" -L"C:\Program Files\ZeroMQ 4.0.4\lib" -llibzmq-v120-mt-4_0_4
mex zmq_cleanup.c -I"C:\Program Files\ZeroMQ 4.0.4\include" -L"C:\Program Files\ZeroMQ 4.0.4\lib" -llibzmq-v120-mt-4_0_4
mex zmq_exec.c -I"C:\Program Files\ZeroMQ 4.0.4\include" -L"C:\Program Files\ZeroMQ 4.0.4\lib" -llibzmq-v120-mt-4_0_4

Then, zmq_cleanup.c and zmq_exec.c need to be modified to declare all variables at the top of the function, as apparently the free Microsoft compiler that comes with SDK 7.1 doesn't support the C99 style of variable declaration.

I didn't try to actually use the matlab-julia interface yet so I don't know if it works but I at least wanted to put the info out there for other Windows users.

-Patrick

@timholy
Copy link
Member

timholy commented Sep 9, 2014

Thanks for posting this! I hope it works for you. These days I use Julia directly, so I don't have recent experience with it, but I'll be pleased if it helps you.

@abhijithch
Copy link

On OS X, the code in make_mex cribbed about not finding zmq.h. Providing the path with the -L and -I options to mex did the trick.

mex -L/usr/local/Cellar/zeromq/4.1.4/lib -I/usr/local/Cellar/zeromq/4.1.4/include -lzmq zmq_connect.c
mex -L/usr/local/Cellar/zeromq/4.1.4/lib -I/usr/local/Cellar/zeromq/4.1.4/include -lzmq zmq_cleanup.c
mex -L/usr/local/Cellar/zeromq/4.1.4/lib -I/usr/local/Cellar/zeromq/4.1.4/include -lzmq zmq_exec.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants