3

我正在尝试在 mex 文件中使用 c++ 静态库,但我无法链接它。

这是我试图混合的 cpp 文件的来源:

#include <math.h>
#include <matrix.h>
#include <mex.h>
#include <iostream>
#include "pbogus.h"



void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
pbogus p;
int x=p.fbogus(2);

 mexPrintf("%d",x);

 }

这是我的“库”的头文件和源代码:

//header
#ifndef PBOGUS_H
#define PBOGUS_H

class pbogus
{

public:
int fbogus(int );
};


#endif


//source
#include "pbogus.h"

int pbogus::fbogus(int x)
{
return 2*x;

}

该库名为testsymcpp.lib

这是我正在使用的 mex 命令:

 mex -v -L. -ltestsymcpp hello.cpp

这是输出:

 This is mex, Copyright 1984-2007 The MathWorks, Inc. 

     -> Default options filename found in C:\Users\mihai\AppData\Roaming\MathWorks\MATLAB\R2008a 
---------------------------------------------------------------- 
->    Options file           = C:\Users\mihai\AppData\Roaming\MathWorks\MATLAB\R2008a\mexopts.bat 
      MATLAB                 = D:\MATLAB\R2008a 
->    COMPILER               = cl 
->    Compiler flags: 
         COMPFLAGS           = -c -Zp8 -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          = -Zi -Fd"hello.mexw64.pdb" 
         arguments           =  
         Name switch         = /Fo 
->    Pre-linking commands   =  
->    LINKER                 = link 
->    Link directives: 
         LINKFLAGS           = /dll /export:mexFunction /MAP /LIBPATH:"D:\MATLAB\R2008a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /implib:C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\templib.x /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 
         LINKDEBUGFLAGS      = /DEBUG /PDB:"hello.mexw64.pdb" 
         LINKFLAGSPOST       =  
         Name directive      = /out:"hello.mexw64" 
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @ 
->    Resource Compiler      = rc /fo "mexversion.res" 
->    Resource Linker        =  
---------------------------------------------------------------- 


--> cl  -c -Zp8 -GR -W3 -EHs -D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE -D_SECURE_SCL=0 -DMATLAB_MEX_FILE -nologo /MD /FoC:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\hello.obj -ID:\MATLAB\R2008a\extern\include -ID:\MATLAB\R2008a\simulink\include -O2 -Oy- -DNDEBUG -DMX_COMPAT_32 D:\scoala\studienarbeit\code\testgrey\hello.cpp 

hello.cpp 
    Contents of C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\mex_tmp.rsp: 
  C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\hello.obj 


--> link /out:"hello.mexw64" /dll /export:mexFunction /MAP /LIBPATH:"D:\MATLAB\R2008a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /implib:C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\templib.x /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  @C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\mex_tmp.rsp  .\testsymcpp.lib  

Microsoft (R) Incremental Linker Version 9.00.30729.01 
Copyright (C) Microsoft Corporation.  All rights reserved. 

C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\hello.obj  
   Creating library C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\templib.x and object C:\Users\mihai\AppData\Local\Temp\mex_NeoKF8\templib.exp 
hello.obj : error LNK2019: unresolved external symbol "public: int __cdecl pbogus::fbogus(int)" (?fbogus@pbogus@@QEAAHH@Z) referenced in function mexFunction 
hello.mexw64 : fatal error LNK1120: 1 unresolved externals 

  D:\MATLAB\R2008A\BIN\MEX.PL: Error: Link of 'hello.mexw64' failed. 

??? Error using ==> mex at 207
Unable to complete successfully.
4

0 回答 0