Weird error for correct code

I’m getting the following error when in submit:

/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `main':
/mnt/exercism-iteration/./test_leap.c:59: multiple definition of `main'; /tmp/ccNdOiMO.o:/mnt/exercism-iteration/./leap.c:4: first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `test_year_not_divisible_by_4_in_common_year':
/mnt/exercism-iteration/./test_leap.c:14:(.text+0x18): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `test_year_divisible_by_2_not_divisible_by_4_in_common_year':
/mnt/exercism-iteration/./test_leap.c:19:(.text+0x44): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `test_year_divisible_by_4_not_divisible_by_100_in_leap_year':
/mnt/exercism-iteration/./test_leap.c:24:(.text+0x70): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `test_year_divisible_by_4_and_5_is_still_a_leap_year':
/mnt/exercism-iteration/./test_leap.c:29:(.text+0x99): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o: in function `test_year_divisible_by_100_not_divisible_by_400_in_common_year':
/mnt/exercism-iteration/./test_leap.c:34:(.text+0xc2): undefined reference to `leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccMiflhP.o:/mnt/exercism-iteration/./test_leap.c:40: more undefined references to `leap_year' follow
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

Cant make any sense of it.

You should not have a main function in the .c file.

Did you read Testing on the C track

1 Like

In addition to what @glennj said, here’s how you can read that error message.
I’ll shorten the paths to make it easier to digest.


The first two lines complain about “multiple definitions” of the function main:

ld: /tmp/ccMiflhP.o: in function `main':
test_leap.c:59: multiple definition of `main'; /tmp/ccNdOiMO.o:leap.c:4: first defined here

One appears in test_leap.c (that’s where the tests live), the other in leap.c (your solution).
There can only be one main() function in a C program. The main() in test_leap.c initializes the testing library, executes the tests, and presents the result. You can read the tests in the online editor under the “Tests” tab.

Your task is to write the function(s) that the tests call, in a way that the tests succeed.
You don’t have to write your own main() function, nor do you have to read input or print a result.


ld: /tmp/ccMiflhP.o: in function `test_year_not_divisible_by_4_in_common_year':
test_leap.c:14:(.text+0x18): undefined reference to `leap_year'
...

The rest of the error message complains that the tests call a function leap_year but that the linker (ld) cannot find that function.

The function has already been declared in the initial stub, in leap.h.
You can access this file in the online editor.

But the function has not yet been defined.
This is where you come into play.
You have to define that function, in the file leap.c.

1 Like

Understood. Thanks.

The resource you linked is for running exercism on your machine. I’m using the online editor.

1 Like