Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
compiling C file: error LNK2019: unresolved external symbol

Subject: compiling C file: error LNK2019: unresolved external symbol

From: Charles Behr

Date: 29 Oct, 2012 20:53:08

Message: 1 of 4

Hi,

I am new to matlab, I need to compile a C file (fast_kmeans_step.c) that is part of an opensource Matlab code.
I use MATLAB 2011a and SDK 7.1 to compile mex files.
The c file come with the following lib files
borland_libmwlapack
lcc_libmwblas
msvc_libmwblas
msvc_libmwlapack

When I run mex in Matlab I receive the following error message

>> mex -v fast_kmeans_step.c libmwblas.lib
-> Default options filename found in C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b
----------------------------------------------------------------
-> Options file = C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b\mexopts.bat
      MATLAB = C:\Program Files\MATLAB\R2011b
-> COMPILER = cl
-> Compiler flags:
         COMPFLAGS = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
         OPTIMFLAGS = /O2 /Oy- /DNDEBUG
         DEBUGFLAGS = /Z7
         arguments =
         Name switch = /Fo
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
         LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map"
         LINKDEBUGFLAGS = /debug /PDB:"fast_kmeans_step.mexw64.pdb"
         LINKFLAGSPOST =
         Name directive = /out:"fast_kmeans_step.mexw64"
         File link directive =
         Lib. link directive =
         Rsp file indicator = @
-> Resource Compiler = rc /fo "mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
 
 
--> cl /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj -I"C:\Program Files\MATLAB\R2011b\extern\include" -I"C:\Program Files\MATLAB\R2011b\simulink\include" /O2 /Oy- /DNDEBUG -DMX_COMPAT_32 fast_kmeans_step.c
 
fast_kmeans_step.c
fast_kmeans_step.c(79) : warning C4013: 'PTR_dgemm' undefined; assuming extern returning int
fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
fast_kmeans_step.c(127) : warning C4101: 'value' : unreferenced local variable
fast_kmeans_step.c(125) : warning C4101: 'singleton' : unreferenced local variable
fast_kmeans_step.c(125) : warning C4101: 'K' : unreferenced local variable
fast_kmeans_step.c(130) : warning C4101: 'junk' : unreferenced local variable
    Contents of C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp:
  C:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj libmwblas.lib
 
 
--> link /out:"fast_kmeans_step.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map" @C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp
 
   Creating library C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x and object C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.exp
fast_kmeans_step.obj : error LNK2019: unresolved external symbol PTR_dgemm referenced in function minus2xty
fast_kmeans_step.mexw64 : fatal error LNK1120: 1 unresolved externals
 
  C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'fast_kmeans_step.mexw64' failed.
 
Error using mex (line 206)
Unable to complete successfully.

Any help would be very appreciated,

Charles

Subject: compiling C file: error LNK2019: unresolved external symbol

From: James Tursa

Date: 29 Oct, 2012 22:20:08

Message: 2 of 4

"Charles Behr" <behr_charles@hotmail.com> wrote in message <k6mqbk$dp5$1@newscl01ah.mathworks.com>...

(snip)

> fast_kmeans_step.obj : error LNK2019: unresolved external symbol PTR_dgemm referenced in function minus2xty
> fast_kmeans_step.mexw64 : fatal error LNK1120: 1 unresolved externals
>
> C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'fast_kmeans_step.mexw64' failed.

I see this line:

  dgemm(&cht, &chn, &mcols, &ncols, &drows, &minus2,
            vects1, &drows, vects2, &drows, &one, output, &mcols);

in the code that I found here:

http://code.google.com/p/spiky/source/browse/spike_sorting/mex/fast_kmeans_step.c?r=64

So the code attempts to call the BLAS routine dgemm (double precision generic matrix multiply). But I don't see any prototype information for dgemm in the code. And you get an error for a missing PTR_dgemm routine. My *guess* is that dgemm has been defined as PTR_dgemm somewhere??? But maybe PTR_dgemm didn't get defined to anything??? Just guesses at this point. Basically, dgemm needs to be either left as dgemm (e.g., for Windows), or defined to be dgemm_ (e.g., for Unix) so that it will match what is actualy in the BLAS library when linked.

HOWEVER, even if you get this part figured out and compiled/linked OK, I strongly suspect that the resulting mex routine will bomb. That is because the type for the integer arguments in the dgemm call are hard-coded above to be int's (very likely 32-bit), but on your 64-bit system the integer arguments in the dgemm call may actually be size_t (very likely 64-bit) in the 64-bit library. So I would not expect the compiled code to work on a 64-bit system even if it did compile and link OK. You would have to manually go in and change all of the integer arguments being passed into the dgemm function to be mwSignedIndex instead of int. E.g., this:

/* Function: minus2xty(double *,double *,double *,PTR_dgemm,int,int,int)
 * ------------------------------------------------------------------
 * Subtracts 2*vects1(:,i)*vects2(:,i)' from each element of output. */
  void minus2xty(double* output, double *vects1, double *vects2,
                 int mcols, int ncols, int drows)
{
    int i, numel;
    double minus2 = -2.0, one = 1.0;

    char chn = 'N', cht = 'T';
      dgemm(&cht, &chn, &mcols, &ncols, &drows, &minus2,
            vects1, &drows, vects2, &drows, &one, output, &mcols);
      numel = ncols*mcols;
    for (i = 0; i < numel; i++) { // Fix roundoff error ...
      if (output[i] < 0) {output[i] = 0;}
    }
}


should be changed to something like this:


/* Function: minus2xty(double *,double *,double *,PTR_dgemm,int,int,int)
 * ------------------------------------------------------------------
 * Subtracts 2*vects1(:,i)*vects2(:,i)' from each element of output. */
  void minus2xty(double* output, double *vects1, double *vects2,
                 int mcols, int ncols, int drows)
{
    int i, numel;
    double minus2 = -2.0, one = 1.0;
    mwSignedIndex mcolsx = mcols, ncolsx = ncols, drowsx = drows;

    char chn = 'N', cht = 'T';
      dgemm(&cht, &chn, &mcolsx, &ncolsx, &drowsx, &minus2,
            vects1, &drowsx, vects2, &drowsx, &one, output, &mcolsx);
      numel = ncols*mcols;
    for (i = 0; i < numel; i++) { // Fix roundoff error ...
      if (output[i] < 0) {output[i] = 0;}
    }
}


James Tursa

Subject: compiling C file: error LNK2019: unresolved external symbol

From: Chandan Reddy

Date: 6 Jul, 2013 17:00:13

Message: 3 of 4

I had the exact same error (I take it you are installing Chronux, specifically spike sorting) and same situation (64 bit Windows, Matlab 2012a, SDK7.1, attempting to mex fast_kmeans_step.c).
Did you get it solved?


"Charles Behr" <behr_charles@hotmail.com> wrote in message <k6mqbk$dp5$1@newscl01ah.mathworks.com>...
> Hi,
>
> I am new to matlab, I need to compile a C file (fast_kmeans_step.c) that is part of an opensource Matlab code.
> I use MATLAB 2011a and SDK 7.1 to compile mex files.
> The c file come with the following lib files
> borland_libmwlapack
> lcc_libmwblas
> msvc_libmwblas
> msvc_libmwlapack
>
> When I run mex in Matlab I receive the following error message
>
> >> mex -v fast_kmeans_step.c libmwblas.lib
> -> Default options filename found in C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b
> ----------------------------------------------------------------
> -> Options file = C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b\mexopts.bat
> MATLAB = C:\Program Files\MATLAB\R2011b
> -> COMPILER = cl
> -> Compiler flags:
> COMPFLAGS = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
> OPTIMFLAGS = /O2 /Oy- /DNDEBUG
> DEBUGFLAGS = /Z7
> arguments =
> Name switch = /Fo
> -> Pre-linking commands =
> -> LINKER = link
> -> Link directives:
> LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map"
> LINKDEBUGFLAGS = /debug /PDB:"fast_kmeans_step.mexw64.pdb"
> LINKFLAGSPOST =
> Name directive = /out:"fast_kmeans_step.mexw64"
> File link directive =
> Lib. link directive =
> Rsp file indicator = @
> -> Resource Compiler = rc /fo "mexversion.res"
> -> Resource Linker =
> ----------------------------------------------------------------
>
>
> --> cl /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj -I"C:\Program Files\MATLAB\R2011b\extern\include" -I"C:\Program Files\MATLAB\R2011b\simulink\include" /O2 /Oy- /DNDEBUG -DMX_COMPAT_32 fast_kmeans_step.c
>
> fast_kmeans_step.c
> fast_kmeans_step.c(79) : warning C4013: 'PTR_dgemm' undefined; assuming extern returning int
> fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
> fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
> fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
> fast_kmeans_step.c(127) : warning C4101: 'value' : unreferenced local variable
> fast_kmeans_step.c(125) : warning C4101: 'singleton' : unreferenced local variable
> fast_kmeans_step.c(125) : warning C4101: 'K' : unreferenced local variable
> fast_kmeans_step.c(130) : warning C4101: 'junk' : unreferenced local variable
> Contents of C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp:
> C:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj libmwblas.lib
>
>
> --> link /out:"fast_kmeans_step.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map" @C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp
>
> Creating library C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x and object C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.exp
> fast_kmeans_step.obj : error LNK2019: unresolved external symbol PTR_dgemm referenced in function minus2xty
> fast_kmeans_step.mexw64 : fatal error LNK1120: 1 unresolved externals
>
> C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'fast_kmeans_step.mexw64' failed.
>
> Error using mex (line 206)
> Unable to complete successfully.
>
> Any help would be very appreciated,
>
> Charles

Subject: compiling C file: error LNK2019: unresolved external symbol

From: kiran.santha@gmail.com

Date: 29 Oct, 2013 13:51:32

Message: 4 of 4

I have similar error.
mex('SPrintF_4_0_sf.c', '-IC:\RW_APPS\ADAPT\v5.3.1\rc_eclipse_372\workspace\KC46_LDS\Logical_Architecture\MBD_Resources\Simulink_Lib')
   Creating library C:\rw_apps\Matlab\Temp\mex_6x2QlQ\templib.x and object C:\rw_apps\Matlab\Temp\mex_6x2QlQ\templib.exp
SPrintF_4_0_sf.obj : error LNK2019: unresolved external symbol LegacyCode_SPrintF_4_0 referenced in function mdlOutputs
SPrintF_4_0_sf.mexw64 : fatal error LNK1120: 1 unresolved externals
 
  C:\RW_APPS\MATLAB\R2012B~1\BIN\MEX.PL: Error: Link of 'SPrintF_4_0_sf.mexw64' failed.

Do you guys have any idea on this how to solve?

Thank You


On Saturday, July 6, 2013 12:00:13 PM UTC-5, Chandan Reddy wrote:
> I had the exact same error (I take it you are installing Chronux, specifically spike sorting) and same situation (64 bit Windows, Matlab 2012a, SDK7.1, attempting to mex fast_kmeans_step.c).
>
> Did you get it solved?
>
>
>
>
>
> "Charles Behr" <behr_charles@hotmail.com> wrote in message <k6mqbk$dp5$1@newscl01ah.mathworks.com>...
>
> > Hi,
>
> >
>
> > I am new to matlab, I need to compile a C file (fast_kmeans_step.c) that is part of an opensource Matlab code.
>
> > I use MATLAB 2011a and SDK 7.1 to compile mex files.
>
> > The c file come with the following lib files
>
> > borland_libmwlapack
>
> > lcc_libmwblas
>
> > msvc_libmwblas
>
> > msvc_libmwlapack
>
> >
>
> > When I run mex in Matlab I receive the following error message
>
> >
>
> > >> mex -v fast_kmeans_step.c libmwblas.lib
>
> > -> Default options filename found in C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b
>
> > ----------------------------------------------------------------
>
> > -> Options file = C:\Users\Charles\AppData\Roaming\MathWorks\MATLAB\R2011b\mexopts.bat
>
> > MATLAB = C:\Program Files\MATLAB\R2011b
>
> > -> COMPILER = cl
>
> > -> Compiler flags:
>
> > COMPFLAGS = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
>
> > OPTIMFLAGS = /O2 /Oy- /DNDEBUG
>
> > DEBUGFLAGS = /Z7
>
> > arguments =
>
> > Name switch = /Fo
>
> > -> Pre-linking commands =
>
> > -> LINKER = link
>
> > -> Link directives:
>
> > LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map"
>
> > LINKDEBUGFLAGS = /debug /PDB:"fast_kmeans_step.mexw64.pdb"
>
> > LINKFLAGSPOST =
>
> > Name directive = /out:"fast_kmeans_step.mexw64"
>
> > File link directive =
>
> > Lib. link directive =
>
> > Rsp file indicator = @
>
> > -> Resource Compiler = rc /fo "mexversion.res"
>
> > -> Resource Linker =
>
> > ----------------------------------------------------------------
>
> >
>
> >
>
> > --> cl /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj -I"C:\Program Files\MATLAB\R2011b\extern\include" -I"C:\Program Files\MATLAB\R2011b\simulink\include" /O2 /Oy- /DNDEBUG -DMX_COMPAT_32 fast_kmeans_step.c
>
> >
>
> > fast_kmeans_step.c
>
> > fast_kmeans_step.c(79) : warning C4013: 'PTR_dgemm' undefined; assuming extern returning int
>
> > fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
>
> > fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
>
> > fast_kmeans_step.c(132) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
>
> > fast_kmeans_step.c(127) : warning C4101: 'value' : unreferenced local variable
>
> > fast_kmeans_step.c(125) : warning C4101: 'singleton' : unreferenced local variable
>
> > fast_kmeans_step.c(125) : warning C4101: 'K' : unreferenced local variable
>
> > fast_kmeans_step.c(130) : warning C4101: 'junk' : unreferenced local variable
>
> > Contents of C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp:
>
> > C:\Users\Charles\AppData\Local\Temp\mex_E09I76\fast_kmeans_step.obj libmwblas.lib
>
> >
>
> >
>
> > --> link /out:"fast_kmeans_step.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x" /MAP:"fast_kmeans_step.mexw64.map" @C:\Users\Charles\AppData\Local\Temp\mex_E09I76\mex_tmp.rsp
>
> >
>
> > Creating library C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.x and object C:\Users\Charles\AppData\Local\Temp\mex_E09I76\templib.exp
>
> > fast_kmeans_step.obj : error LNK2019: unresolved external symbol PTR_dgemm referenced in function minus2xty
>
> > fast_kmeans_step.mexw64 : fatal error LNK1120: 1 unresolved externals
>
> >
>
> > C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'fast_kmeans_step.mexw64' failed.
>
> >
>
> > Error using mex (line 206)
>
> > Unable to complete successfully.
>
> >
>
> > Any help would be very appreciated,
>
> >
>
> > Charles

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us