Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about using "extern "C"" to the readme #137

Open
bricktsre opened this issue Dec 19, 2024 · 0 comments
Open

Add information about using "extern "C"" to the readme #137

bricktsre opened this issue Dec 19, 2024 · 0 comments

Comments

@bricktsre
Copy link

I am using a FakeObj.h file to DECLARE the fakes and a FakeObj.c file to DEFINE the fakes. Then I can include the fakes in multiple different files each representing a different test suite. A further complication is my testing code uses gtest and therefore C++ while fff uses C. I ran into some linker issues about not being able to find the _reset functions of the fakes. This was caused by C/C++ name mangling of the functions. The solution to this was to add a extern "C" wrapper to the header file like so

#ifdef __cplusplus
extern "C" {
#endif

DECLARE_FAKE_VALUE_FUNC(func_a);
DECLARE_FAKE_VOID_FUNC(func_b);

// List of fakes used by these unit tests
#define FFF_FAKES_LIST(FUNC)    \
    FUNC(func_a)                            \
    FUNC(func_b) 


#ifdef __cplusplus
}
#endif

I would advocate adding this information to the readme in the "How do I reuse a fake across multiple test-suites?" section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant