ThrowTheSwitch / Ceedling

Ruby-based unit testing and build system for C projects

Home Page:http://throwtheswitch.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Header with multiple source files

RengXian opened this issue · comments

I'm trying to include a header file that is linked to multiple source files in my ceedling test but I'm getting undefined reference for the interface that park under the header file. In other words, the source files are not compiled thus failed at linker stage.

For example:
common_api.h consists of two API:
void common_first(void);
void common_second(void);

and the APIs are defined in two different .c file as below:

  1. common_first.c
    void common_first(void){ /implementation/ };

  2. common_second.c
    void common_second(void){ /implementation/ };

When I include the common_api.h in my test file, I'm getting undefined reference for common_first() and common_second().

My question is:

  1. Is it mandatory to have same header and source name when executing ceedling?

I saw in discussions that the suggestion was to make dummy .h files with the same name as the .c file. At least just for testing purposes, so that Ceedling is able to read it.

It's not mandatory so much as it's a convenience for telling Ceedling which files it is going to need to compile. If you have matching heading files for those, it's worth doing this, because then it will know for sure:

#include "common_api.h"
#include "common_first.h"
#include "common_second.h"

It will search for any C file matching the above headers and automatically include them in your test.

In your situation, it sounds like the latter files don't exist. No worries. You can still tell Ceedling what to put there:

#include "common_api.h"
TEST_FILE("common_first.c")
TEST_FILE("common_second.c")

In this case, it's important that common_api.h has the declarations for the functions (which you do). The Test is only going to look at common_api.h as a header, but it will link to both of the other two files when it reaches the linker step.