justingardner / mgl

A suite of mex/m files for displaying psychophysics stimuli
http://justingardner.net/mgl
Other
18 stars 22 forks source link

Compile Issues with MATLAB 2017a #20

Closed JustinChavez closed 2 years ago

JustinChavez commented 7 years ago

mgl worked fine for my project on MATLAB 2016a. I just updated to 2017a and it create an issue where it seems to be stuck at the MEX file computation and freezes the program.

When I try to recompile the MEX files with mglMake, it brings a bunch of errors that have the same pattern like so

>> mglMake(1)
(mglMake) No specific mex options found for sdk version 10.12, using generic options
(mglMake) Using standrad options for mex
mex  mglBindFrameBufferObject.c
Building with 'Xcode with Clang'.
Error compiling mglBindFrameBufferObject.c
Error using mex
In file included from /Users/Justin_C/Desktop/gold/mgl/mgllib/mglBindFrameBufferObject.c:20:
In file included from /Users/Justin_C/Desktop/gold/mgl/mgllib/mgl.h:94:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1: error: expected identifier or '('
@class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:494:9: error: unknown type name 'NSString'
typedef NSString * NSExceptionName NS_EXTENSIBLE_STRING_ENUM;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:495:9: error: unknown type name 'NSString'
typedef NSString * NSRunLoopMode NS_EXTENSIBLE_STRING_ENUM;

Most errors follow the pattern of not being able to find NSString, Protocol, or NS_FORMAT_FUNCTION.

Any tips on how to fix this error?

Many thanks in advance!

justingardner commented 7 years ago

Looks like you may need to modify your mexopts file - as these are problems with linking to the right libraries. The “Xcode with Clang” might be problematic - as the code uses Objective-C constructs (NSString for example). Might google around to see what you need to set in mexopts to insure proper compliation of Objective-C for your setup.

-j.

Justin L. Gardner, PhD Assistant Professor, Department of Psychology, Stanford University Jordan Hall, Building 01-420 450 Serra Mall, Stanford CA 94305 https://gru.stanford.edu

On Jun 29, 2017, at 6:08 AM, Justin Chavez notifications@github.com wrote:

mgl worked fine for my project on MATLAB 2016a. I just updated to 2017a and it create an issue where it seems to be stuck at the MEX file computation and freezes the program.

When I try to recompile the MEX files with mglMake, it brings a bunch of errors that have the same pattern like so

mglMake(1) (mglMake) No specific mex options found for sdk version 10.12, using generic options (mglMake) Using standrad options for mex mex mglBindFrameBufferObject.c Building with 'Xcode with Clang'. Error compiling mglBindFrameBufferObject.c Error using mex In file included from /Users/Justin_C/Desktop/gold/mgl/mgllib/mglBindFrameBufferObject.c:20: In file included from /Users/Justin_C/Desktop/gold/mgl/mgllib/mgl.h:94: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:8: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:492:1: error: expected identifier or '(' @class NSString, Protocol; ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:494:9: error: unknown type name 'NSString' typedef NSString NSExceptionName NS_EXTENSIBLE_STRING_ENUM; ^ /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:495:9: error: unknown type name 'NSString' typedef NSString NSRunLoopMode NS_EXTENSIBLE_STRING_ENUM; Most errors follow the pattern of not being able to find NSString, Protocol, or NS_FORMAT_FUNCTION.

Any tips on how to fix this error?

Many thanks in advance!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/justingardner/mgl/issues/20, or mute the thread https://github.com/notifications/unsubscribe-auth/AHePo40K40e5edHLFocgJdAWUCQDiBbCks5sIsDkgaJpZM4OIiRM.

lukehallum commented 7 years ago

Hi Justin & Justin,

Here are some notes I sent to Manu Raghavan; we were trouble shooting similar compile errors. This may not be our final solution, but we're up and running in the meantime.

HTH, Luke

Out of the box, MGL (v2.0) compiles with errors on my laptop (El Capitan 10.11.3; SDK 10.11; Xcode 7.3; compiler /usr/bin/clang).

The compiler balked at a "@class NSString;" statement. That's, of course, not C but rather Objective-C. The flag -ObjC ("Treat source input files as Objective-C") needs to be added to the compile step.

The notionally simple addition of this flag to the compile step rapidly became problematic. The MGL v2.0 distro includes several scripts (e.g., mexopt.10.7.xcode.4.3.sh) used to configure the mex compiler when mglMake() is called from the Matlab prompt. But there's no script pertaining to SDK 10.11, Xcode 7.3, and furthermore recent distros of Matlab seem not to use shell scripts for mex configuration but rather to use xml files instead.

Matlab's default mex config xml can be found in directory /Applications/MATLAB9.0.app/bin/maci64/mexopts. I copied clang_maci64.xml to my local directory mgl/mgllib and modified the following lines, adding -ObjC and all the -framework stuff:

CFLAGS="-fno-common -arch x86_64 -mmacosx-version-min=$SDKVER -fexceptions -isysroot $ISYSROOT -ObjC"

LDFLAGS1="-Wl,-twolevel_namespace -undefined error -arch x86_64 -mmacosx-version-min=$SDKVER -Wl,-syslibroot,$ISYSROOT $LDBUNDLE $LINKEXPORT"

LDFLAGS="$LDFLAGS1 -bundle -framework Foundation -framework agl -framework Carbon -framework Cocoa -framework CoreServices -framework openGL -framework QTKit"

I added the following 2 lines to mglMake.m at the obvious spot to do so (where mex configuration scripts/files are defined):

elseif sdkVersion == 10.11 optf = '-f /Users/luke/mgl/mgllib/clang_maci64.xml';

justingardner commented 7 years ago

Thanks luke - can you make a pull request of this, so that I can merge?

JustinChavez commented 7 years ago

Thanks for the help Luke. I was able to compile the mex files with your specified edits.

Unfortunately, I must note that while Mac sdkVersion 10.11 seems to function, version 10.12 still has fatal errors. It may be due to some recent deprecations such as CGDisplayModeCopyPixelEncoding (deprecated in 10.12).

This is used in mglResolution and returns:

Error using mglResolution
Requested 4294967297x1 (192.0GB) array exceeds maximum array size preference. 
Creation of arrays greater than thislimit may take a long time and cause MATLAB to 
become unresponsive. See array size limit or preference panel for more information.

I noticed a similar error in mglPrivateGetGammaTable.

I was able to overcome these errors by using -compatibleArrayDims (R2017a MEX builds with a 64 bit API by default, this flag reverts back to the original 32 bit API) in mglMake.m like so:

elseif sdkVersion == 10.12
optf = '-compatibleArrayDims -f ./clang_maci64.xml';

But, the code still seems to break somewhere else.

I may just look into converting the MEX files to 64-bit compatibility as suggested online.

In the meantime I will downgrade to get some tasks up and running for the PI!

justingardner commented 2 years ago

Closing this out. We are now working on a new version of mgl (based on metal) and the compilation scripts have been updated to mglMakeMetal.