Question

In: Computer Science

4.2.1 Dynamic linking in practice Here you must write a program that in the simplest way...

4.2.1 Dynamic linking in practice 

Here you must write a program that in the simplest way demonstrates the principle by having the instruction sequence of two different functions' only accessible through two different, dynamically linked, libraries (which you have built yourself). 

The program has the following specification: 
-All prints are made to the command prompt window.
-Each printout step is followed by a line feed and carriage return. 
-At program start "Program start" is written
-The program then calls a function located in one of the two dynamically linked libraries. This function prints "I.dll number one." 
-The program then calls a function located in the other dynamically linked library. This function prints out "I.dll number two."
- The program exits.

This exercise has nothing to do with linked lists, its only about dynamic linking of libraries.

The code should be in C programming language and every step should be well commented for good understanding!

Solutions

Expert Solution

I have provided separate code for each file as asked in the question. I have also added comments in all the code snippets for clear and better understanding of the answer. Please find the answer attached below.

Ans) This is the first dll file and is called the "first_dll.c"

/* This is the first dll file and is called the "first_dll.c" */

#include<stdio.h>    // This is for standard input and ouput 

#include "first_dll.h"   // This preprocessor directive tells the compilet to include or access "first_dll.h" in "first_dll.c"

EXPORT void first_print(void){    

/* This is the print statement which the question demands and 

the EXPORT keyword is defined in "first_dll.h" file */

printf (" I.dll number one \r\n");   

//The print statement has the carriage return and line feed as expected in the question

}

The code below is the header file for the program "first_dll.c" which has the definition for the header file "first_dll.h" EXPORT keyword

/*  Consider the file "first_dll.h" */

#define EXPORT __declspec(dllexport) 

/* The  __declspec(dllexport) is a DLL export directive which helps the linker to ger the function first_pirnt() in the "first_dll.c" program */
EXPORT void first_print(void);

NOW lets write the second DLL files in the similar manner :

/* This is the second dll file and is called the "second_dll.c" */

#include<stdio.h>    // This is for standard input and ouput 

#include "second_dll.h"   // This preprocessor directive tells the compilet to include or access "second_dll.h" in "second_dll.c"
EXPORT void second_print(void){   

/* This is the print statement which the question demands and

the EXPORT keyword is defined in "second_dll.h" file */

printf (" I.dll number two \r\n");   

//The print statement has the carriage return and line feed as expected in the question

}

The code below is the header file for the program "second_dll.c" which has the definition for the header file "second_dll.h" and EXPORT keyword :

/*  Consider the following code for file "second_dll.h" */

#define EXPORT __declspec(dllexport)

/* The  __declspec(dllexport) is a DLL export directive which helps the linker to ger the function second_print() in the "second_dll.c" program */

EXPORT void second_print(void);

Now consider the main program "dll_linking.c" which calls the methods from dll written above :

/*program "dll_linking.c" which calls the methods from dll  */

#include "first_dll.h" 
#include "second_dll.h" 

int main() {

printf(" \n Program start \r\n ");   // the question says this message should be printed 

first_print(); /* calling the function from dll1 i.e first_dll.c 
which in turn has header of first_dll.h.This wil print "I.dll number one" with carriage return and line feed */  

second_print();  /* calling the function from dll2 i.e second_dll.c 
which in turn has header of second_dll.h. This wil print "I.dll number two" with carriage return and line feed */  


return 0; //exit the program

}
/* NOTE THAT : The dll files should be compiled using the commands -->

gcc -c first_dll.c 

gcc -shared -o First_Dll.dll -Wl,--out-implib,libtstdll.a first_dll.o

and 

gcc -c second_dll.c

gcc -shared -o Second_Dll.dll -Wl,--out-implib,libtstdll.a second_dll.o

and for main program use commands-->

gcc -o dll_linking main.c -L. -lFirst_Dll -lSecond_Dll

*/
 

Related Solutions

can you please explain to me in simplest way that i can understand the cyert and...
can you please explain to me in simplest way that i can understand the cyert and march behaviour theory. kindly give an example for it. thank you so much.
Write the simplest program possible in your language of choice containing your 'main' and any other...
Write the simplest program possible in your language of choice containing your 'main' and any other functions you may need that will: A. Read a sequence of words up to a maximum of 64 words from std input. Before reading the input, prompt the user to enter the words. B. Check to see if there any duplicate words in the input read. C. If there are no duplicates, print out to std output the message 'No Duplicates'. D. If there...
You are asked to write a simple C++ phonebook application program. Here are the requirements for...
You are asked to write a simple C++ phonebook application program. Here are the requirements for the application. read the contact information from a given input file (phonebook.txt) into a dynamically created array of Contact objects. Each line of the input line includes name and phone information of a contact. Assume that each name has a single part Allow to perform operations on array of data such as search for a person, create a new contact or delete an existing...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
what is profit maximization model? can you kindly explain it in simplest way that i can...
what is profit maximization model? can you kindly explain it in simplest way that i can understand it and give an example of it?
The goal of this project is to practice (Write a C Program) with a function that...
The goal of this project is to practice (Write a C Program) with a function that one of its parameter is a function.The prototype of this function is: void func ( float (*f)(float*, int), float* a, int length); This means the function: func has three parameters: float (*f)(float*, int): This parameter itself is a function: f that has two parameters and returns a floating-point number. In the body of the function: func we call the function: f with its arguments...
This program must be done in JAVA. Write a program to monitor the flow of an...
This program must be done in JAVA. Write a program to monitor the flow of an item into an out of a warehouse. The warehouse has numerous deliveries and shipments for this item (a widget) during the time period covered. A shipment out (an order) is billed at a profit of 50% over the cost of the widget. Unfortunately each incoming shipment may have a different cost associated with it. The accountants of the firm have instituted a last-in, first...
In this exercise we will practice using nested loops. You will write s program that prompts...
In this exercise we will practice using nested loops. You will write s program that prompts the user to enter an integer between 1 and 9 and displays a pyramid of numbers, as shown in the example below. The program must validate the input given by the user and make sure that: if the user enters a non-integer the program issues an error message and requests the user provides a valid input. if the user does not enter a number...
Write a program that reads in the name and salary of an employee. Here the salary...
Write a program that reads in the name and salary of an employee. Here the salary will denote an hourly wage, such as $9.25. Then, ask how many hours the employee worked in the past week. Be sure to accept fractional hours. Compute the pay. Any overtime work (over 40 hours per week) is paid at 150 percent of the regular wage.4 pts Your code with comments A screenshot of the execution Test Cases: Enter name: Jorge Enter wage: 9.25...
This document describes a computer program you must write in Python and submit to Gradescope. For...
This document describes a computer program you must write in Python and submit to Gradescope. For this project, the program will simulate the operation of a vending machine that sells snacks, accepting coins and dispensing products and change. In an actual vending machine, a program running on an embedded computer accepts input from buttons (e.g. a numeric keypad) and devices such as coin acceptors, and its output consists of signals that control a display, actuate motors to dispense products, etc.....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT