问题
I'm trying to debug a C++ OS X application in XCode 5.1 (5B130a) under OS X 10.9.2. The application is composed of various library projects that get compiled into libraries and used in a main application project.
I set a breakpoint in my code and when I run in lldb:
expr 2
this is what I get:
(lldb) expr 2
error: field '__f_' declared with incompatible types in different translation units ('__base *' (aka 'std::__1::__function::__base<void (std::__1::shared_ptr<const XXX>, const YYY &)> *') vs. '__base *' (aka 'std::__1::__function::__base<void> *'))
error: field '__f_' declared with incompatible types in different translation units ('__base *' (aka 'std::__1::__function::__base<void (std::__1::shared_ptr<const XXX>, const YYY &)> *') vs. '__base *' (aka 'std::__1::__function::__base<void> *'))
error: expected expression
note: declared here with type '__base *' (aka 'std::__1::__function::__base<void> *')
note: declared here with type '__base *' (aka 'std::__1::__function::__base<void> *')
error: 3 errors parsing expression
Please note that if I set the breakpoint somewhere else in the code, the same command might work (but not everywhere). This leads me to think that the specific library that I'm breaking in makes a difference.
I understand that somewhere there is a definition for std::function<void(std::shared_ptr<const XXX>, const YYY&)>
and that some other translation unit sees it with a different definition, (I believe the __f_
is an internal field of the std::function templated class), however it's not clear to me:
- why doesn't the linker complain about it? (in fact, the app is running perfectly)
- what code generation switch mismatch could cause this? I already checked
GCC_OPTIMIZATION_LEVEL
(all-O0
),COPY_PHASE_STRIP
, ...
Thanks!
回答1:
This is most likely a problem with the debug information rather than with the generated code, which is why your app runs correctly but the expression evaluator in the debugger fails.
The debugger always tries to read the least amount of debug information it needs to in order to do whatever you ask it to. So until you do something that causes us to read in the two modules that have disagreeing debug information, you won't see this problem. That's why it sometimes happens and sometimes doesn't.
Anyway, please file a bug about this with bugreporter.apple.com.
来源:https://stackoverflow.com/questions/22969143/llvm-reports-error-declared-with-incompatible-types-in-different-translation-uni