libcheck / check

A unit testing framework for C
GNU Lesser General Public License v2.1
1.07k stars 209 forks source link

Can't compile on Ubuntu with Codeblocks #343

Closed joegasewicz closed 1 year ago

joegasewicz commented 1 year ago

I cloned the repo and ran these cmds successfully:

$ mkdir build
$ cd build
$ cmake ../
$ make
$ CTEST_OUTPUT_ON_FAILURE=1 make test

Build log


-------------- Build: Debug in tests (compiler: GNU GCC Compiler)---------------

[100.0%] gcc  -o bin/Debug/tests obj/Debug/main.o   /home/joe/Documents/Projects/adt_tools/bin/Debug/libadt_tools.a /usr/local/lib/libcheck.a /usr/local/lib/libcheck.so /usr/lib/x86_64-linux-gnu/libcheck.a /usr/lib/x86_64-linux-gnu/libcheck_pic.a
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o): in function `tcase_create':
/home/joe/Codeblocks/check/src/check.c:148: undefined reference to `floor'
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o): in function `tcase_set_timeout':
/home/joe/Codeblocks/check/src/check.c:335: undefined reference to `floor'
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o): in function `check_get_clockid':
/home/joe/Codeblocks/check/src/check.c:614: undefined reference to `timer_create'
/usr/bin/ld: /home/joe/Codeblocks/check/src/check.c:616: undefined reference to `timer_delete'
/usr/bin/ld: /usr/local/lib/libcheck.a(check_pack.o): in function `ppack':
/home/joe/Codeblocks/check/src/check_pack.c:379: undefined reference to `__pthread_register_cancel'
/usr/bin/ld: /home/joe/Codeblocks/check/src/check_pack.c:384: undefined reference to `__pthread_unregister_cancel'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
7 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Build messages

||=== Build: Debug in tests (compiler: GNU GCC Compiler) ===|
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o)||in function `tcase_create':|
/home/joe/Codeblocks/check/src/check.c|148|undefined reference to `floor'|
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o)||in function `tcase_set_timeout':|
/home/joe/Codeblocks/check/src/check.c|335|undefined reference to `floor'|
/usr/bin/ld: /usr/local/lib/libcheck.a(check.o)||in function `check_get_clockid':|
/home/joe/Codeblocks/check/src/check.c|614|undefined reference to `timer_create'|
/usr/bin/ld: /home/joe/Codeblocks/check/src/check.c|616|undefined reference to `timer_delete'|
/usr/bin/ld: /usr/local/lib/libcheck.a(check_pack.o)||in function `ppack':|
/home/joe/Codeblocks/check/src/check_pack.c|379|undefined reference to `__pthread_register_cancel'|
/usr/bin/ld: /home/joe/Codeblocks/check/src/check_pack.c|384|undefined reference to `__pthread_unregister_cancel'|
||error: ld returned 1 exit status|
||=== Build failed: 7 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

I have added /usr/local/lib/libcheck.a to the linker settings & /usr/lib to the "Search directories" in Codeblocks. But it seems like where i cloned and ran the Makefile cmds the error seems to be tyring at least to look for the header files in the local cloned check repo directory?

In check.c on line 21 - #include "../lib/libcompat.h" - could this be where it's failing to pull in the header files?

joegasewicz commented 1 year ago

Found a solution, might help someone else... Goto Project > Build Options > linker settings and in the 'other link options' panel add pkg-config --cflags --libs check inside back tick quotes.