Redifinition error

2 次查看(过去 30 天)
Amit Kalhapure
Amit Kalhapure 2012-6-8
I have a cpp code that runs well in VS2010. When I try to run it on Matlab 2010a by using mex command, it gives redefinition error.
c:\users\amit\documents\matlab\real_c++\redacmodel.cpp(20) : error C2371: 'FORCE' : redefinition; different basic types
c:\users\amit\documents\matlab\real_c++\blueacmodel.cpp(20) : see declaration of 'FORCE'
What is the reason? Thanks in advance.

回答(1 个)

Walter Roberson
Walter Roberson 2012-6-8
I would speculate that FORCE is an "extern" variable in the two .cpp files.
The two .cpp files define FORCE with different data types. Look at line 20 of each of the two different source files to see how it is defined for the two.
  4 个评论
Walter Roberson
Walter Roberson 2012-6-9
You can find an unofficial copy of ISO C at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf
Amit Kalhapure
Amit Kalhapure 2012-6-9
Thanks for your reply, I have found another solution for this problem
If I use following command then I'm able to get rid of redefinition error.
mex -v mesh.cpp blueacmodel.cpp redacmodel.cpp
mesh.cpp is the main source code here. but the new error I'm getting now is
LINK : error LNK2001: unresolved external symbol mexFunction
C:\USERS\AMIT\APPDATA\LOCAL\TEMP\MEX_3K~1\templib.x : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Link of 'mesh.mexw32' failed.
What to do?
Thanks again.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Call C++ from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by