Hi!
I want to build a static library (.lib) with some subroutines to be used by my s-function. As a simple test, this library (let's call it mylib) only contains a subroutine (let's call it subrout) that sums its two inputs and outputs the solution.
This library was built with Microsoft Visual Studio 2005 Professional Edition.
Once in Matlab, I add the library to the same directory in which I am working. Then I use the mex command in the following way "mex sfunction.c mylib.lib".
While compiling I get:" warning c4013: 'subrout' undefined; assuming extern returning int ".
While linking I get "error LNK2019: unresolved external symbol _subrout referenced in function _mdlOutputs."
I have had this error in the past and it was always because I forgot to include some library or it wasn't in its right place. In dispair I even added the library directly in the linker flags in MEXOPTS.bat; still the problem remains. For this reason I think that the possibility of Matlab not "seeing" the library could be ruled out.
Does anyone have any idea about how to solve this problem? Could it be some definition I missed while building the library in Microsoft Visual Studio?
Thanks in advance for your help,
Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
5/25/2010 4:16:24 PM |
|
"Bruno " <brocaaugusto@hotmail.com> wrote in message <htgt4o$rl$1@fred.mathworks.com>...
>
> Once in Matlab, I add the library to the same directory in which I am working. Then I use the mex command in the following way "mex sfunction.c mylib.lib".
>
> While compiling I get:" warning c4013: 'subrout' undefined; assuming extern returning int ".
You are missing a prototype for the function subrout. The first time the compiler sees this function reference is when it is called, so it assumes it is an extern function returning int. You should put prototypes for *all* of your functions at the beginning of your code.
> While linking I get "error LNK2019: unresolved external symbol _subrout referenced in function _mdlOutputs."
How was the library mylib.lib compiled? Is the subrout name actually exported so the linker can see it?
James Tursa
|
|
0
|
|
|
|
Reply
|
James
|
5/25/2010 5:24:10 PM
|
|
"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hth13q$6k5$1@fred.mathworks.com>...
> "Bruno " <brocaaugusto@hotmail.com> wrote in message <htgt4o$rl$1@fred.mathworks.com>...
> >
> > Once in Matlab, I add the library to the same directory in which I am working. Then I use the mex command in the following way "mex sfunction.c mylib.lib".
> >
> > While compiling I get:" warning c4013: 'subrout' undefined; assuming extern returning int ".
>
> You are missing a prototype for the function subrout. The first time the compiler sees this function reference is when it is called, so it assumes it is an extern function returning int. You should put prototypes for *all* of your functions at the beginning of your code.
>
> > While linking I get "error LNK2019: unresolved external symbol _subrout referenced in function _mdlOutputs."
>
> How was the library mylib.lib compiled? Is the subrout name actually exported so the linker can see it?
>
> James Tursa
Hi James!
Thank for your reply. I will add prototypes to fix that warning. In what concerns the compiling of mylib.lib, I created a new win32 project in Visual Studio and selected static library. Then, added my .c file with the definition of subrout and a .h file with its declaration. Finally I built the project with no errors or warnings. I do not know how to make sure the name subrout was exported so that the linker sees it.
I don't know if the compiler flags help, but here they are:
"/O2 /GL /D "WIN32" /D "NDEBUG" /D "_LIB" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MD /Zc:wchar_t- /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Zi /TC /errorReport:prompt"
Best Regards,
Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
5/25/2010 6:06:08 PM
|
|
"Bruno " <brocaaugusto@hotmail.com> wrote in message <hth3ig$lhb$1@fred.mathworks.com>...
> "James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <hth13q$6k5$1@fred.mathworks.com>...
> > "Bruno " <brocaaugusto@hotmail.com> wrote in message <htgt4o$rl$1@fred.mathworks.com>...
> > >
> > > Once in Matlab, I add the library to the same directory in which I am working. Then I use the mex command in the following way "mex sfunction.c mylib.lib".
> > >
> > > While compiling I get:" warning c4013: 'subrout' undefined; assuming extern returning int ".
> >
> > You are missing a prototype for the function subrout. The first time the compiler sees this function reference is when it is called, so it assumes it is an extern function returning int. You should put prototypes for *all* of your functions at the beginning of your code.
> >
> > > While linking I get "error LNK2019: unresolved external symbol _subrout referenced in function _mdlOutputs."
> >
> > How was the library mylib.lib compiled? Is the subrout name actually exported so the linker can see it?
> >
> > James Tursa
>
> Hi James!
>
> Thank for your reply. I will add prototypes to fix that warning. In what concerns the compiling of mylib.lib, I created a new win32 project in Visual Studio and selected static library. Then, added my .c file with the definition of subrout and a .h file with its declaration. Finally I built the project with no errors or warnings. I do not know how to make sure the name subrout was exported so that the linker sees it.
>
> I don't know if the compiler flags help, but here they are:
> "/O2 /GL /D "WIN32" /D "NDEBUG" /D "_LIB" /D "_UNICODE" /D "UNICODE" /FD /EHsc /MD /Zc:wchar_t- /Fo"Release\\" /Fd"Release\vc80.pdb" /W3 /nologo /c /Zi /TC /errorReport:prompt"
>
> Best Regards,
> Bruno
I figured out that I acctually did not export the subrout so that the linker could see it. Everything seems to working now. Thank you very much for your tip.
Bruno
|
|
0
|
|
|
|
Reply
|
Bruno
|
5/26/2010 8:37:03 AM
|
|
|
3 Replies
472 Views
(page loaded in 0.047 seconds)
Similiar Articles: Creating static libs to use in mex - comp.soft-sys.matlab ...matlab crashes (win 7 64 bit) without messages, logs or dumps ..... used modified gnumex to create .def and .lib files ... write,compile,link and run mex files ... Debugging C MEX S-functions with Visual Studio .NET - comp.soft ...Creating static libs to use in mex - comp.soft-sys.matlab ..... lib) with some subroutines to be used by my s-function. ... mylib.lib, I created a new win32 project in ... Static library created from MASM to link to Visual C++ app - comp ...Creating static libs to use in mex - comp.soft-sys.matlab ... Static library created from MASM to link to Visual C++ app - comp ... You must reference the static library ... lcc compiler is missing in windows 7(32 bit) in matlab 2007b ...Creating static libs to use in mex - comp.soft-sys.matlab ... > > You are missing a prototype for the ... MEX in Matlab 7.10, 64 bit, Windows 7 - comp.soft-sys.matlab ..... ... static library + undefined reference problem - comp.compilers.lcc ...Creating static libs to use in mex - comp.soft-sys.matlab ... static library + undefined reference problem - comp.compilers.lcc ..... reference to '__debuglevel' Please ... matlab crashes (win 7 64 bit) without messages, logs or dumps ...... write,compile,link and run mex files. > Moreover, I compiled the itpp library with msys/mingw and created static libs as ... used modified gnumex to create .def and .lib files ... Mex File: fatal error LNK1120: 7 unresolved externals - comp.soft ...I am making mex file out of tsnnls_test1.cpp and all relevant headers are ... nowrap.lib libf2c.lib BLASd_nowrap.lib clapackd_nowrap.lib libf2cd.lib Creating ... Static Linking Problem - comp.unix.programmerSolaris doesn't support such use from static executables. ... libdl and libc as dynamic, and if you want static for your libs ... messages, logs or dumps ..... link and run mex ... How to create two executables with one makefile? - comp.unix ...>> LIBS = >> TARGET1 = tbclient.exe >> WXCONFIG ... How to create a list with multiple occurences of a ... ... two executables compile and link with these static ... mex and intel compiler - comp.soft-sys.matlab... ignored Creating library C:\DOCUME~1\WARNED\LOCALS~1\TEMP\MEX ... LOCALS~1\TEMP\MEX_RN~1\templib.exp MSVCRT.lib ... 2010a to use MS Visual C++ 2010 Express as mex ... Creating static libs to use in mex - Newsreader - MATLAB CentralFile exchange, MATLAB Answers, newsgroup access, Links, and Blogs for the MATLAB & Simulink user community Creating static libs to use in mex - comp.soft-sys.matlab ...matlab crashes (win 7 64 bit) without messages, logs or dumps ..... used modified gnumex to create .def and .lib files ... write,compile,link and run mex files ... 7/23/2012 4:56:10 PM
|