Suppose you have a C program whose main function is in mainc

Suppose you have a C program whose main function is in main.c and has other functions in the files input.c and output.c:

a) What command(s) would you use on your system to compile and link this program?

b) How would you modify the above commands to link a library called process1 stored in the standard system library directory?

c) How would you modify the above commands to link a library called process2 stored in your home directory?

d) Some header files need to be read and have been found to be located in a header subdirectory of your home directory and also in the current working directory. How would you modify the compiler commands to account for this?

Solution

a)

//To link 2 external files within a c program.This will only work if the files are present in current directory

# include \"input.c\"

#include\"output.c\"

//To compile the program in vi editor

In terminal type cc filename.c

If math.h is included,then use cc filename.c -lm

to insert a data press i

to save and quit press :wq where w means save and q means quit

to create a file vi filename.c

for execution ./a.out

b) use #include<proces1> //use angular brackets to look in standard system library directory

Suppose you have a C program whose main function is in main.c and has other functions in the files input.c and output.c: a) What command(s) would you use on you

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site