Ex 32 (No shared library)

I have gone through the book and code a few times but the lib named liblcthw.so in build is not there. The makefile runs and the tests run (all fine)… I do get a warning that argc from the minunit.c is declared but not used. I am at a loss here. I been hunting backwards and forwards even using the code from the GIT repository, no luck. Any suggestions ?

So I suspect something is up with the Makefile, I copied and pasted it from the GIT and it isn’t building. Appears to be with the linker. It can’t find the -lsbsd option. When I run the command in the book from your output the lib builds ok.

OS=$(shell lsb_release -si)
ifeq ($(OS),Ubuntu)
	LDLIBS=-llcthw -lbsd -L./build -lm

Sorry for the plethora of posts … turns out that my library wasn’t being compiled because the commands to do so in the GIT version of the Makefile were removed (I don’t know if the later exercises modify it) . So I am now getting the argc error, but I looked over everything and it seems to be right. Error is below and then the Run TESTS macro is after that.

In file included from tests/list_tests.c:1:0:
tests/list_tests.c: In function ‘main’:
tests/minunit.h:15:38: warning: parameter ‘argc’ set but not used [-Wunused-but-set-parameter]
 #define RUN_TESTS(name) int main(int argc, char *argv[]) {\
tests/list_tests.c:108:1: note: in expansion of macro ‘RUN_TESTS’
#define RUN_TESTS(name) int main(int argc, char *argv[]) {argc = 1; \
    debug("----- RUNNING: %s", argv[0]);\
    printf("----\nRUNNING: %s\n", argv[0]);\
    char *result = name();\
    if (result != 0) {\
        printf("FAILED: %s\n", result);\
    else {\
        printf("ALL TESTS PASSED\n");\
    printf("Tests run: %d\n", tests_run);\
    exit(result != 0);\

int tests_run;


I fixed your code for you. You can edit posts by hitting the … and then click the pencil. It looks like you had the ``` around your code which is fine, but you didn’t do it right so your code was mangled.

Now, this error is telling you exactly what it says. There’s an option to the compiler to flag unused variables, and you aren’t using argc. Find a way to toss in an argc usage or remove that flag and you’re good to go.

How so … argc is set to 1.

#define RUN_TESTS(name) int main(int argc, char *argv[]) {argc = 1; \

Well you don’t have to set it, just use it. You can add it to the debug printing on that first line and that’ll work.

1 Like

Ok, I thought ‘setting it’ in a sense was ‘using’ it, hence I would not or should not receive the warning. You say in the text of your book, that it should compile with not warnings or errors so I was concerned (not overly). The more important is the Makefile. It differs from what you have in the book as opposed to what you have in your GIT for this exercise . Not sure if its worth checking out, I don’t want others falling into the same problems I did. Thanks for all your help of course. Not trying to be needy :slight_smile: just trying to be successful :).

Yes, you want to try to get it to compile without any warnings or errors. This warning though is a little annoying as an error. It’s a good warning, but honestly so many functions don’t use arguments that it’s kind of noise. But it’s good practice to silence them all in useful ways.