couldn't run codegen under matlab

I have trial version of matlab coder,and download a sample coder from mathwork: hello_world. and followed the instruction of how to setup and run the sample.
when I tried to run codegen to generate mex function within matlab, I get a error message like: >> codegen hello_world ??? cp: preserving permissions for `/var/local/scratch/qguan/coder2/coderdemo_hello_world/codegen/mex/hello_world/mexopts.sh': Operation not supported
I checked uid and gid for the current workfolder, it is set all fine and rw enabled.
what else I should be looking into? or is it known issue?
Thanks so much for your help! Qingyan

 Accepted Answer

The codegen command uses
>> copyfile(<source_file>,<dest_dir>,'f')
to copy mexopts.sh, which is typically found in [matlabroot '/bin']. You could try executing this command to see if it fails.
If the issue is related to permissions, you might try running mex -setup. This can be used to copy mexopts.sh to your prefdir (to which I presume you have write permission) and you could then modify the permissions on the file in your prefdir. The codegen command will give preference to the mexopts.sh file in the prefdir over the one in the bin directory.
-John

6 Comments

I noticed that copyfile(localfile,localfile) is ok, but when source_file is from NFS, it fails.
so here is source_file in NFS mounted directory:
>> ls -l /mnt/home/qguan/.matlab/R2011a/mexopts.sh
-rwxr-xr-x+ 1 qguan qguan 9358 2011-05-26 11:43 mexopts.sh
Here is dist_file in local directory:
>>ls -l codegen/mex/hello_world/mexopts.sh
-rwxr-xr-x 1 qguan qguan 9358 2011-05-26 11:43 codegen/mex/hello_world/mexopts.sh
They are all the same.
what did you suggest me to modify permission at this point?
I said above "Sometimes preserving permissions is not possible with networked file systems." and you indicated in response, "it is all local file system". Please clarify whether networked file systems are or are not involved.
sorry, I thought it is copying file from matlabroot/bin, so it would be local. then I discovered it is actually copying from home directory matlab working folder, something like:
~/.matlab/R2011a/mexopts.sh
So it is networked file system involved.
and I think it involves copyfile() command in matlab script, which I don't know how to remove option -p.
Insert a new "cp" earlier on your PATH that strips out the -p and passes the rest to the real cp ;-)
as this is a matlab code, it only uses copyfile(), which actually run cp -p in OS system. doesn't that mean that I have modify matlab function copyfile()? otherwise, I don't know how to strip out the -p.
I think what I will do is to modify matlab startup folder, so it can land to local directory, to avoid involving NFS files.
Thanks everyone for help!
If it actually invokes "cp" then the operating system is going to use the PATH environment variable to search for "cp". If you have provided a PATH environment variable that first lists a different directory that has your own version of "cp" in it, the operating system would look there first. The program you have in that location could process the arguments, remove the "-p" and start the _real_ "cp" program with those arguments.
But changing your start-up directory is probably easier ;-)

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 25 May 2011
It sounds as if at some point the script is executing the Linux command
cp -p SomeFile /var/local/scratch/qguan/coder2/coderdemo_hello_world/codegen/mex/hello_world/mexopts.sh
(Or --preserve instead of -p)
and that for some reason keeping the permissions is not possible.
Sometimes preserving permissions is not possible with networked file systems.
What I would probably do is fine the "cp" line and remove the "-p" or "--preserve" option.

6 Comments

yes, the most google search result would lead to cp -p option issue. I don't why this could happen. it is all local file system. and I run cp -p at regular term, and it executed it successfully. it only complains within matlab console.
also, I have no idea which script it is trying to run. it is of course matlab related question. codegen under matlab seems a binary file, so I can't really modify it.
any idea?
Could it be that there is a firewall-like software that doesn't allow MATLAB to run with the same privileges as when you run from shell?
Firewall-like software seems unlikely for Linux.
Differences in operation are possible if codegen or something it exec()'s is suid or sgid for some reason.
I can tell from the message that "cp" itself is being executed at some level. You could probably determine where using Linux's strace.
I removed sgid from the working folder,it still does not work.
Under matlab the command copyfile is equivalent to unix command cp -p, so I run copyfile function under matlab console, it seems working fine.
Walter, could you show me how to do the strace to get idea which script it is running.
The documentation for copyfile is inconsistent with copyfile being equivalent to cp -p . The copyfile documentation indicates, "The read-only and archive attributes of source are not preserved in destination." but the point of cp -p is to preserve at least the read-only attribute.
@Qingyan: Have you tried running either:
!cp -p /some/source /some/destination
or
system('cp -p /some/source /some/destination')
Do they work okay?

Sign in to comment.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!