You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using OCMock in Objective–C++ test classes, linking the tests fails under certain circumstances with an error like the following:
Undefined symbols for architecture x86_64:
"OCMMakeLocation(objc_object*, char const*, int)", referenced from:
-[D12AwesomenessTests testThatObjCxxWithOCMockIsAwesome] in D12AwesomenessTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The reason for this is simple and can be found in <OCMock/OCMMakeLocation.h>: extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line);
This function is declared extern, but not extern "C" as it would need to.
Foundation and the other Apple frameworks solve this by defining a macro like the following:
And all exported C functions are subsequently declared this way.
Motivation
As you’re well aware of, Swift is somewhat hostile to mocking. On the C++’s auto keyword, on the other hand, significantly reduces the amount of boilerplate you have to write in an “Objective–C Generics” world.
So using Objective–C++ for tests with OCMock seem like a perfect match; in theory.
In practice, not reliably being able to link your tests depending on inclusion order or something like that is a bit of a downer.
The text was updated successfully, but these errors were encountered:
danyowdee
added a commit
to danyowdee/ocmock
that referenced
this issue
Sep 14, 2015
As detailed in erikdoe#238, linking tests sometimes fails when OCMock is being used in Objective-C++ (.mm) test case files.
This commit solves that problem by conditionally declaring `OCMMakeLocation` as `extern C` in when included in a C++ compilation unit.
Thanks for pulling, even after you went the more exhausted route!
I considered the macro wasn't worth it because I only saw this one public function, but it sure does read nicer that way. Sorry for the inconvenience this caused!
Issue
When using OCMock in Objective–C++ test classes, linking the tests fails under certain circumstances with an error like the following:
The reason for this is simple and can be found in
<OCMock/OCMMakeLocation.h>
:extern OCMLocation *OCMMakeLocation(id testCase, const char *file, int line);
This function is declared
extern
, but notextern "C"
as it would need to.Foundation and the other Apple frameworks solve this by defining a macro like the following:
And all exported C functions are subsequently declared this way.
Motivation
As you’re well aware of, Swift is somewhat hostile to mocking. On the C++’s
auto
keyword, on the other hand, significantly reduces the amount of boilerplate you have to write in an “Objective–C Generics” world.So using Objective–C++ for tests with OCMock seem like a perfect match; in theory.
In practice, not reliably being able to link your tests depending on inclusion order or something like that is a bit of a downer.
The text was updated successfully, but these errors were encountered: