Pregunta

I have some C unit tests with check framework.

My Makefile.am looks like:

check_PROGRAMS = check_fseqs
check_fseqs_SOURCES = tests/check_fseqs.c
check_fseqs_LDADD = -lcheck

File structure is (some files were omitted):

.
|-- Makefile.am
|-- configure.ac
|-- src
|   |-- fseqs.c
|   |-- fseqs.h
|   |-- fseqs.o
`-- tests
    `-- check_fseqs.c

Then I run make check and it throws:

$ make check
/Applications/Xcode.app/Contents/Developer/usr/bin/make  check_fseqs
gcc  -g -O2   -o check_fseqs tests/check_fseqs.o -lcheck 
Undefined symbols for architecture x86_64:
  "_f_msb", referenced from:
      _test_f_msb in check_fseqs.o
  "_min", referenced from:
      _test_min in check_fseqs.o
  "_substract", referenced from:
      _test_substract in check_fseqs.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [check_fseqs] Error 1
make: *** [check-am] Error 2

What is wrong?

¿Fue útil?

Solución

You're missing a dependency. If you're building fseqs.o, you need to add it as check_DEPENDENCIES and also add it to your check_LDADD line. If it was a library, you'd do the same thing, specifying the library file instead of all of the object files making the library up.

The check_DEPENDENCIES bit ensures the correct rule is generated, and the check_LDADD ensures the file is added to the command line while linking.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top