I'm having trouble with these files:
Code:
/* File peptide.c */
#include <stdio.h>
#include <stdlib.h>
#include "residues.c"
/* Simulate a peptide sequence and report its hydropathy index */
int main(void) {
puts("Your peptide sequence is\n");
puts(strcat(sequence(), " ."));
puts("\n\n");
printf("Cumulative hydropathy: %f;\n"
"average hydropathy: %2.1f.\n", hp, hp/20.);
}
/* --------------- */
/* File residues.c */
#include "peptide.h"
char* sequence(void) {
int aaLeft = 20;
char* seq = "NH2-"; /* Build from the N-terminus of the chain. */
seq = malloc(120 * sizeof(char));
while(aaLeft--) {
int aa;
aa = random() % 20; /* Randomly choose an amino acid from the list */
seq = strcat(seq, residue[aa]);
hp += hpi[aa];
}
seq = strcat(seq, "COOH"); /* We're done */
return seq;
}
/* --------------- */
/* File peptide.h */
#include <stdio.h>
#include <stdlib.h>
char* residue[20] = { "Ile-", "Val-", "Leu-", "Phe-", "Cys-", "Met-",
"Ala-", "Gly-", "Thr-", "Ser-", "Trp-", "Tyr-",
"Pro-", "Gln-", "Asn-", "Asp-", "Glu-", "His-",
"Lys-", "Arg-" };
float hpi[20] = { 4.5, 4.2, 3.8, 2.8, 2.5, 1.9,
1.8, -0.4, -0.7, -0.8, -0.9, -1.3,
-1.6, -3.5, -3.5, -3.5, -3.5, -3.2,
-3.9, -4.5 };
extern float hp; /* Running count of the hydropathy. */
/* That's all, folks... */
Here's what happens when I try to compile and link:
Code:
127.0.0.1> gcc -o peptide residues.c peptide.c
/tmp/cclu2H5r.o(.data+0x0): multiple definition of `residue'
/tmp/ccU47JJi.o(.data+0x0): first defined here
/tmp/cclu2H5r.o(.data+0x60): multiple definition of `hpi'
/tmp/ccU47JJi.o(.data+0x60): first defined here
/tmp/cclu2H5r.o(.text+0x0): In function `sequence':
: multiple definition of `sequence'
/tmp/ccU47JJi.o(.text+0x0): first defined here
/tmp/ccU47JJi.o(.text+0x65): In function `sequence':
: undefined reference to `hp'
/tmp/ccU47JJi.o(.text+0x72): In function `sequence':
: undefined reference to `hp'
/tmp/cclu2H5r.o(.text+0x65): In function `sequence':
: undefined reference to `hp'
/tmp/cclu2H5r.o(.text+0x72): In function `sequence':
: undefined reference to `hp'
/tmp/cclu2H5r.o(.text+0x100): In function `main':
: undefined reference to `hp'
/tmp/cclu2H5r.o(.text+0x115): more undefined references to `hp' follow
collect2: ld returned 1 exit status
Thanks.