Redifinition error
이전 댓글 표시
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
2012년 6월 8일
0 개 추천
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
Amit Kalhapure
2012년 6월 9일
Walter Roberson
2012년 6월 9일
That does not declare a structure variable: that declares a type alias named FORCE .
It appears you might be running into a problem with ISO C section 6.7.2.3 "Tags", paragraph 4:
Two declarations of structure, union, or enumerated types which are in different scopes or
use different tags declare distinct types. Each declaration of a structure, union, or
enumerated type which does not include a tag declares a distinct type.
The two FORCE are thus considered to be different types, and if a single scope saw both definitions then it would be an error, a redefinition of FORCE.
Please check whether one of those two files #include's the other: they probably should not.
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
2012년 6월 9일
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!