6

I started to use check framework for testing C application. For better understanding I went across the example in check package. It is working fine, but I don't need the automake tools - I want to compile it by my own Makefile (since I want to understand the check properly and I need to use my final application as a package of an OS). Maybe I could use there the autogenerated Makefile, but for now, it would be next one new thing I have to learn and I have restricted time for preparing unit tests. (Then, of course, I want to study and understand the tools for generating Makfile, using configure, etc.)

There is a problem in building application with my Makefile, that I don't have linked the object for check functionality:

/tmp/ccm7cniy.o: In function `test_money_create':
check_money.c:(.text+0x1e): undefined reference to `tcase_fn_start'
check_money.c:(.text+0x79): undefined reference to `_fail_unless'
check_money.c:(.text+0xcc): undefined reference to `_fail_unless'

I found out, that in the example application is the gcc with obj. file check_money-check_money.o, which was created by gcc:

gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT check_money-check_money.o -MD -MP -MF .deps/check_money-check_money.Tpo -c -o check_money-check_money.o `test -f'check_money.c' || echo './'`check_money.c

And here is my problem: it uses the dependency check_money-check_money.Tpo. This file was generating by the command ./configure, which I don't use.

How can I create my own .o file for check to build successfully? It is necessary to create this file for every application? Could not be one, somewhere in shared libraries?

(I am sorry if my question is "stupid", I have small experience by building applications in linux yet)

sth
  • 222,467
  • 53
  • 283
  • 367
srnka
  • 1,275
  • 2
  • 12
  • 16
  • 2
    Have you installed the check framework? If you have, you could try using `pkg-config` say `gcc check_money.c \`pkg-config --cflags --libs check\`` – another.anon.coward Mar 15 '12 at 09:20
  • the gcc option `-MF bla.Tpo` contains the building dependencies, [see here -M](http://gcc.gnu.org/onlinedocs/gcc-4.6.3/gcc/Preprocessor-Options.html#Preprocessor-Options). So if you correctly specify all libs and dependencies by hand you don't need that. Judging from the error, you don't link versus the check library. Tr another.anon.coward's pkg command. This usually returns the necessary include paths and libraries. – Bort Mar 15 '12 at 09:49
  • @another.anon.coward - Thank you! - it resolved this problem – srnka Mar 15 '12 at 10:08
  • @another.anon.coward - can you, please, write your answer as answer, so I can mark it as correct and this question won't stay without correct answer. (Or should I write the answer to it myself?) Thanks – srnka Mar 16 '12 at 16:36

1 Answers1

8

Adding comment as response:
Please check if you have installed check framework. If so, you could try using pkg-config say

gcc check_money.c `pkg-config --cflags --libs check`

Here pkg-config utility will read the .pc file (which happens to be check.pc in case of check framework, thus the last entry in the command says check) & add the necessary compiler flags (--cflags option) & libraries/linker options (--libs option)

Hope this helps!

another.anon.coward
  • 11,087
  • 1
  • 32
  • 38