agostino
Uploaded by
1 SLIDES
148 VIEWS
10LIKES

Multiple File Compilation and Linking

DESCRIPTION

This document explains how to compile and link multiple C source files using pthreads along with custom headers. It includes a sample code demonstrating the integration of two headers, `mars.h` and `venus.h`, and showcases basic threading and function definitions. The program calculates the square of a number using `doA` from `mars.h` and executes a threaded function `doB` from `venus.h`. Students and developers will learn the structure of multi-file projects, linking libraries, and handling threads in C.

1 / 1

Download Presentation

Multiple File Compilation and Linking

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Multiple File Compilation and Linking pthread.h stdio.h mars.h venus.h #ifndef STDIO_H #define STDIO_H #endif #ifndef PTHREAD_H #define PTHREAD_H #endif #ifndef MARS_HEADER #define MARS_HEADER #define MIN 1000 int doA(int nbr); #endif #ifndef VENUS_HEADER #define VENUS_HEADER typedef struct { // fields } gravityType; void doB(char symbol); #endif programX.c #include <stdio.h> #include <pthread.h> #include “mars.h” #include “venus.h” main()‏ { gravityType value; pthread_t threadID; int result; printf(“Hello”); result = doA(5); doB(‘d’); } // End main mars.c venus.c #include <stdio.h> #include “mars.h” int doA(int nbr)‏ { return nbr * nbr; } // End doA #include “venus.h” #include <pthread.h> #define MAX 100 void doB(char symbol)‏ { pthread_t threads[MAX]; } // End doB programX.o libc.a libpthread.a mars.o venus.o Object code file The Standard C Library Threads library Object code file Object code file a.out gcc programX.c mars.c venus.c Executable File

More Related