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...
In java please, thank you :) For this assignment, you will continue your practice with dynamic...
In java please, thank you :) For this assignment, you will continue your practice with dynamic structures. Specifically, you will be implementing a different version of a linked-list, called a Queue. Queues are very important and useful linear structures that are used in many applications. Follow the link below for a detailed description: tutorialspoint - Queue (Links to an external site.) The queue description above uses an array implementation for examples. As usual you will be not be using arrays,...
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?
Can someone design a Tic Tac Toe game in java in the simplest way you can?...
Can someone design a Tic Tac Toe game in java in the simplest way you can? It should have -the markers for the players are X and O -2 players -instructions on how to play the game in the start of the game -show the Tic Tac Toe grid before asking each player for their input -be on one java file Thank you!!!!!!! This is for an intro class so please don't make it too complicated!
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT