Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:46:16+00:00 2026-06-11T20:46:16+00:00

I’m having the problem with CMockery mocks that there are coming duplicate symbol warnings.

  • 0

I’m having the problem with CMockery mocks that there are coming duplicate symbol warnings.

The implementation of the code is quite long, so it’s in a Gist here.

The Gist includes the test (.c), implementation (.c) and header file, the project is build with CMake and tested with CTest, using CMockery.

The actual error is:

ld: duplicate symbol _wit_configuration_file_path in ../libwatchedit.a(configuration.c.o) and CMakeFiles/libwatcheditTest.dir/configuration_test.c.o for architecture x86_64

The work-around I was able to come up with was to declare char *wit_configuration_file_path() as static. As the implementation is in the same file as the implementation of int wit_load_configuration(wit_configuration config) I expected that would work, it does in fact compile and link cleanly. Unfortunately though, and likely as a side-effect of declaring wit_configuration_file_path() as static, it never uses the mock.

The google examples for cmockery are too contrived, and to not explain how one should deal with this.

It’s also possible that it would be smarter, and easier to test to declare the function not as :

int wit_load_configuration(wit_configuration config);

but rather as:

int wit_load_configuration(char* filepath, wit_configuration, config);

In which case, I don’t need to mock or stub anything; but I believe that the problem will come back to bite me, as I expect that I’ll need to mock something in the future (otherwise how could one write comprehensive unit tests?)

1: How should I do this properly, static means it never uses my mock, declaring it without static causes duplicate symbol errors.

2: Should I change the design of my API? It would work for this case, but I’d like to know how to mock a function properly.

3: Is it a mistake to link my tests against my whole library, I’m using CMake, and the line target_link_libraries(libwatcheditTest watchedit) in my test’s CMakeLists.txt.

Update: I added some more build output here for help with diagnosis

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:46:17+00:00Added an answer on June 11, 2026 at 8:46 pm

    You try to mock out *wit_configuration_file_path* with is in the same source file as the function under test *wit_load_configuration*. This is not possible. The linker sees the original implementation of wit_configuration_file_path and also the mocked version.

    CMockery has a pretty course grained scope for the mocking. In the end, you can only mock out complete source files. If two functions are in the same source file, they are either both mocked out or they are both in the “System under Test”.

    What to do in this case? Don’t mock out *wit_configuration_file_path* or place it in a different source file. As *wit_load_configuration* and *wit_configuration_file_path* are so highly related, probably not mocking the function out would be the best solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.