UnbescholtenerBuerger
UnbescholtenerBuerger

Reputation: 318

Integrating a library in eclipse stops the debug exe from running as expected

I am trying to set up a C project with cmocka unit test framework in eclipse. Following software is used:

I create a new default Hello World ANSI C Project in eclipse called "cmocka_test". It compiles, it is debuggable and it prints out to the console.

Then, I expand the project to include the cmocka library by doing the following:

  1. I extract the contents of cmocka-1.1.0-mingw.zip ( https://cmocka.org/files/1.1/ ) into the project folder
  2. I add the "include" path to project Properties -> C/C++ Build -> Settings -> GCC C Compiler -> Includes
  3. I add the "lib" path to project Properties -> C/C++ Build -> Settings -> MinGW C Linker -> Libraries -> Library search path and "cmocka" to -> Libraries -> Libraries (-l)
  4. The code is modified to include a simple cmocka testcase:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

static void null_test_success(void **state) {
    (void) state; /* unused */
    int test = 4;
    assert_int_equal(test, 5);

}
int main(void) {
    printf("Hello");
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(null_test_success),
    };
    return cmocka_run_group_tests(tests, NULL, NULL);
}

It compiles fine, this is the console output:

12:30:17 **** Rebuild of configuration Debug for project cmocka_test ****
Info: Internal Builder is used for build
gcc "-IC:\\Users\\UnbescholtenerBuerger\\eclipse-workspace\\cmocka_test\\cmocka\\cmocka-1.1.0\\include" -O0 -g3 -pedantic -Wall -c -fmessage-length=0 -o "src\\cmocka_test.o" "..\\src\\cmocka_test.c" 
gcc "-LC:\\Program Files (x86)\\cmocka\\lib" -o cmocka_test.exe "src\\cmocka_test.o" -lcmocka 

However, debugging/running does not work as expected. CLicking on the debug symbol in eclipse does not bring me to the start of the main() function. It does not stop at breakpoints that I set. It does not write 'Hello' to the console, neither does it inform about a failed test case. No console output, no problems or warnings. I just immediately get the info <terminated, exit value: 0> gdb (7.6.1) in the debug view. And in the Debugger console (which I never used before):

[New Thread 18044.0x3020]
[New Thread 18044.0x598]
[New Thread 18044.0x38f0]
Thread ID 0 not known.
Thread ID 0 not known.
Thread ID 0 not known.

What am I missing here?


per request of user the busybee, here the gcc commands from makefile:

gcc -c -Icmocka/cmocka-1.0.0/include -g -o ut_test.o C:/Users/UnbescholtenerBuerger/eclipse-workspace/ut_test/src/ut_test.c
gcc -Lcmocka/cmocka-1.0.0/bin -lcmocka -g -o ut_test ut_test.o

Results are the same.

Upvotes: 2

Views: 168

Answers (0)

Related Questions