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.
After doing a
make allfrom the top level Makefile, cd into thesoup/directory and create following test C program,bar.c:Compile this code and run with:
The above command compiles and links
barand the./barexecutable 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 barThe above command will fail to link
bardue to Undefined symbols.Now compile this same code, again, WITHOUT FUN but this time with some additional libraries:
This time, the code, WITHOUT FUN will compile and link. And of course, without the fun call,
barjust exits as expected.IMPORTANT POINT: Calling the
vrergfB(-1, -1)function (i.e., some FUN) allows one to linkbarwith only a few libraries. By REMOVING THE CALL tovrergfB(-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.cis 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.