Operating System - Linux
1753753 Members
5309 Online
108799 Solutions
New Discussion

Re: Use of function prototypes when linking C code

 
Joe_452
New Member

Use of function prototypes when linking C code

Hi, I'd appreciate any insights into this behaviour of the CC compiler.

Hypothetically, I have a function named "myfunc" declared in a library named "mylib.a". In "mysource.c", I'm making use of "myfunc" but I didn't specify a function prototype for it.

When I go about compiling "mysource.c", I would get an "Unsatisfied symbols" error which is all as expected.

A problem arises if I first compile "mysource.c" into "mysource.o" and then linking it with "mylib.a" to generate the executable. There were no errors eventhough the function prototype for "myfunc" is missing.

My questions as follows:
- How does the compiler perform type checking for "myfunc"?
- Is there an option to force the compiler to complain about the missing prototype? (some sort fo an GCC -Wmissing-prototypes equivalent?)

Thanks in advance.
1 REPLY 1
Muthukumar_5
Honored Contributor

Re: Use of function prototypes when linking C code

a) Linking of libraries are related to Link editor. It is checking for the type checking of functions with program and libraries. It is the one generating error's as "Unsatisfied symbols".

You can test it as,

# cc -v mysource.c -o mysource
# cc -v mysource.c -o mysource

It will give details.

b) Change Linker editor ld settings with,

+k Direct the linker to only create an executable if
there were no errors encountered during the link.
If there were errors found (system errors or
unresolved references), the output file will be
removed.

+n Causes the linker to load all object modules
before searching any archive or shared libraries.
Then it searches the archive and shared libraries
specified on the command line in left to right
order. Repeats the left to right search of the
libraries on the command line until there are no
more unsatisfied symbols, or the last search added
no new definitions. This option is useful if two
libraries are specified that have symbol
dependencies on each other.

hth.
Easy to suggest when don't know about the problem!