0

Back again, this time trying to figure out pset3. I think everone is familiar with the pset, but for anyone who isn't, I'm trying to convert a fraction (1/8, 1/4, 1/2, etc) to a number of eighths.

This is what I have for the duration portion of the code:

#include <cs50.h>
#include <string.h>

#include "helpers.h"

// Converts a fraction formatted as X/Y to eighths
int duration(string fraction)
{
// TODO
// get fraction
//grab numerator
//grab denominator
//get denominator to == 8
//multiply numerator by the same number you multiplied the denominator
int denom = fraction[2] - 48;
int numer = fraction[0] - 48;
int multiplier;

//after checking stackexchancge, seems like int num = (8 * nom) / dom; would also replace this if nest
if (denom == 8) {
    multiplier = 1;
} else if (denom == 4) {
    multiplier = 2;
} else if (denom == 2) {
    multiplier = 4;
} else {
    return 1;
}

int dur = numer * multiplier;
return dur;
}

The code then goes on to frequency (haven't started it yet) and is_rest, but I won't copy the whole thing over since I think the problem lies in duration. Anyways, I did the whole duration bit in a scratchpad file and it ran fine, but when I copied it over to the helpers.c file it refused to work. This is the error message I get:

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 21
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_line): relocation 0 has invalid symbol index 2
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [helpers] Error 1

I don't understand the error code, and I can't use help50 since I can't make helpers yet. Can someone help me out and point me in the right direction here? This pset is really throwing me for a loop.

Thanks!

0

helpers.c has no main function, is not meant to build an executable. When you type make helpers (did you mention how you tried to compile?), it will try to guess a compile command based on the existence of a file helpers.c as the likely source and a built-in rule, and fail.

Use make synthesize or make notes to build one of the executables, or make all for both, or just make for first target in makefile (which happens to be all).

0

This series of errors usually means that an attempt was made to compile a source code file that doesn't have a main() code block.

In this case, I'm thinking that you tried to compile helpers.c by running the command make helpers. This isn't going to work. You need to compile a main program, not the helpers file. This can be accomplished by making any of the individual programs using a command like make notes or make synthesize, or now that there's a makefile, you could just run the command make.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance, ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .