Question: I'm having trouble with compiling this c code. The code I'm trying to compile is called serialize.c #include #include #include #include helpers.h #define RAND_RANGE 4

I'm having trouble with compiling this c code.

The code I'm trying to compile is called serialize.c

#include #include #include

#include "helpers.h"

#define RAND_RANGE 4

/* NOTE: This program does nothing useful. It just reads from STDIN, emits * to STDOUT, and occasionally reports that it fails ... */ int main() { int retval = read_data();

srand(time(NULL)); if (retval < 0 || rand() % RAND_RANGE == 0) { printf("Failed "); return 1; } return 0; }

I also have helpers.h

#ifndef HELPER_H

#define HELPER_H

#define BUF_SIZE 1024

int read_data();

#endif

I also have helpers.c

#include

#include "helpers.h"

int read_data() { char buffer[BUF_SIZE]; int retval;

while ((retval = fread(buffer, 1, BUF_SIZE, stdin)) == BUF_SIZE);

return retval; }

When I run "gcc -Wall -o asdf serialize.c", I get the errors:

undefined reference to 'read_data'

and

error ld returned 1 exit status.

Why is that?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!