Skip to content

Explain: Why does soap/bar.c require links to additional libraries when FUN is NOT defined? #1317

@lcn2

Description

@lcn2

After doing a make all from the top level Makefile, cd into the soup/ directory and create following test C program, bar.c:

/*
 * bar - not defining FUN forces one to link additional libraries
 */

#include "foo.h"
#include "file_util.h"

int
main(void)
{
#if defined(FUN)
    vrergfB(-1, -1);
#endif
    return count_dirs(".");
}

Compile this code and run with:

cc -DFUN bar.c -c && cc bar.o ./soup.a ../dbg/libdbg.a -lm -o bar && ./bar

The above command compiles and links bar and the ./bar executable prints a fun message.

Now try to compile this same code WITHOUT FUN:

cc -UFUN bar.c -c && cc bar.o ./soup.a ../dbg/libdbg.a -lm -o bar

The above command will fail to link bar due to Undefined symbols.

Now compile this same code, again, WITHOUT FUN but this time with some additional libraries:

cc -UFUN bar.c -c && cc bar.o ./soup.a ../dbg/libdbg.a -lm \
    ../dyn_array/libdyn_array.a ../jparse/libjparse.a -lm -o bar && ./bar

This time, the code, WITHOUT FUN will compile and link. And of course, without the fun call, bar just exits as expected.

IMPORTANT POINT: Calling the vrergfB(-1, -1) function (i.e., some FUN) allows one to link bar with only a few libraries. By REMOVING THE CALL to vrergfB(-1, -1) function (i.e., without FUN), one is FORCED to link in additional libraries.

The task

Please explain WHY not defining FUN forces one to link additional libraries.

Is there some problem within this repo that causes this bizarre linking behavior? If so, what is needed to have a more library linkage dependency?

PLEASE NOTE: The bar.c is just a small test case. The goal of this task is to NOT to fix bar, nor is the goal move code into some external library as some form of "workaround". The goal is to explain this behavior, and once the behavior is understood, recommend any changes to this repo that might prevent this bizarre behavior from occurring.

This is a background priority task.

UPDATE 0

As things have moved around in this repo, use the code references in GH issuecomment-3416192644 instead of the code mentioned above.

Metadata

Metadata

Assignees

Labels

background priorityWhile this issue is needs to be solved, it is of a somewhat lower priority.help wantedExtra attention is neededquestionFurther information is requested

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions