Page 1 of 1

Configuring MATLAB R14 SP2/SP3 and R2006a to work with VC8

PostPosted: Wed May 20, 2009 12:03 pm
by snyder
MATLAB R14 SP2/SP3 does not detect newer versions of VC after VC6.0 when running "mex -setup". MATLAB R2006a will detect newer versions of VC but will give you linker errors when you try to execute code. In order to get R14SP2 to work with VC8 for instance I had to perform the following changes by hand. These changes work for me but your mileage may vary.

R14 SP2/SP3 - follow steps 1 and 2
R2006a - follow step 2

1) (R14 SP2/SP3 only) Add an environment variable to "trick" MATLAB into using the grt_vc.tmf template as the default. To do this we need to get the get_tmf_for_target MATLAB method to return grt_vc.tmf. This is done by adding any one of these variables into your Windows environment: 'DEVSTUDIO', 'MSDevDir','MSVCDir'. I just used the value of '%DevEnvDir%' which should exist for a VC8 installation but I believe any text would work fine.

At this point things will start to work better but you will get the following error when trying to generate and execute tests from sl2tvec:

LINK : fatal error LNK1181: cannot open input file 'libcp.lib'

This is corrected in step 2.

2) Fixing the "LINK : fatal error LNK1181: cannot open input file 'libcp.lib'" error.
Edit the grt_vc.tmf file. My file was located here: C:\Program Files\MATLAB\R14SP2\rtw\c\grt\grt_vc.tmf. Search for this line:

LDFLAGS = $(ldebug) $(conflags) $(EXT_LIB) $(conlibs) libcp.lib

and change it to:

LDFLAGS = $(ldebug) $(conflags) $(EXT_LIB) $(conlibs) libcpmt.lib /NODEFAULTLIB:libc.lib

which includes the multi-threaded libcpmt.lib file. The libcp.lib file is the old single threaded stdlib which is not part of the new versions of VC. libc.lib is the old single-threaded c run time lib which does not exist in the new versions of VC. The /NODEFAULTLIB:libc.lib instructs the linker to not try and include that library if any of the other libraries tried to include it.

For ERT target you need to edit ert_vc.tmf. Mine was located here: C:\Program Files\MATLAB\R14SP2\rtw\c\ert\ert_vc.tmf
Change:
$(LD) $(LDFLAGS) $(S_FUNCTIONS_LIB) $(SHARED_LIB) $(LIBS) @$(CMD_FILE) -out:$@
to:
$(LD) $(LDFLAGS) $(S_FUNCTIONS_LIB) $(SHARED_LIB) $(LIBS) /NODEFAULTLIB:libc.lib @$(CMD_FILE) -out:$@

You should now be able to generate and execute tests from the sl2tvec GUI.

Re: Configuring MATLAB R14 SP2/SP3 and R2006a to work with VC8

PostPosted: Wed Jul 15, 2009 5:11 pm
by snyder
In R14 SP2 or SP3, If you see an error about "*** Created" not found it appears to be related to a change in the way nmake is handling the string "***". The "***" is being expanded into a list of all the files being processed causing a string search to fail. It only occurred in two of my models but I could not determine why. It has an easy fix though. Edit the following files:

grt_vc.tmf file. My file was located here: C:\Program Files\MATLAB\R14SP2\rtw\c\grt\grt_vc.tmf
ert_vc.tmf file. My file was located here: C:\Program Files\MATLAB\R14SP2\rtw\c\ert\ert_vc.tmf
modelrefsim_vc.tmf file. My file was located here: C:\Program Files\MATLAB\R14SP2\rtw\c\modelref\modelrefsim_vc.tmf

and change the line:
BUILD_SUCCESS = *** Created

to something like:
BUILD_SUCCESS = c*c*c* Created

save files and run. The error will no longer occur.