Featured post
compiler construction - Detect undefined symbols in C header file -
suposse coded c library provides bunch of "public" functions, declared in mylib.h
header file. functions supposedly implemented in (say) mylib.c
file compiled (say) static lib mylib.c -> mylib.o -> mylib.a
.
is there way detect forgot provide implementation of declared function in mylib.h
? (yes, know unit testing, practices, etc - and, yes, understand meaning of plain function declaration in c).
suppose mylib.h
declares void func1();
, function not coded in provided library. trigger error if linker needs use function. otherwise, compile ok , without warnings - afaik. there way (perhaps compiler dependent) trigger warning declared not implemented functions, or there other way deal issue?
btw: nm -u lists not undefined declared functions, "used" library, i.e., functions trigger error in linking phase if not declared somewhere. (which makes sense, library object file not know header files, of course.)
basically, reliable way have program (or possibly series of programs) formally exercise each , every 1 of functions. if 1 of programs fails link because of missing symbol, you've goofed.
i suppose try editing copy of header source file (as in, file ending .c
), converting function declarations dummy function definitions:
original:
extern int somefunc(void);
revised:
extern int somefunc(void){}
then compile modified source minimum warnings - , ignore "function supposed return value doesn't". compare defined symbols in object file revised source defined symbols in library (using nm -g
on unix-like systems). present in object file isn't present in library missing , should supplied.
note: if header includes other headers of own define functions, need process of those. if header includes standard headers such <stdio.h>
, won't defining functions such fopen()
or printf()
in ordinary course of events. so, choose headers reprocess source code carefully.
- Get link
- X
- Other Apps
Comments
Post a Comment