DOC PREVIEW
CORNELL CS 404 - CREATING DYNAMICALLY-LINKED LIBRARIES

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS 404: Lab 4: Creating Dynamically-LinkedLibrariesGetting Started1. We will be doing this lab in Windows, so boot to that operating systemand log in.2. Open a web browse r and go to the course website1. Download DLL-test.tar.3. Double clicking on the tar file will launch WinZip (it may launch theWinZip set-up application first, go ahead and set it up). Click “Ex-tract” and place the contents in the S drive.Building a DLL1. Open VisualC++ 6.0 from the Startup menu. You need to create twoprojects: one to build the DLL and the other to build the program.To create the DLL project, select “New” from the “File” menu. Clickon the “Projects” tab to display a selection of several project types.Select “Win32 Dynamic-Link Library.” Then, give the project a name( I used testDLL), and choose the location where the project will beplaced (I selected the DLLtest directory). Click OK. You will then beasked what kind of DLL you’d like to create. Answer “Empty” (theothers will give you sample code and will set the compiler options to doWindows things, none of which we want). You will then see a summaryof what you’ve selected, click OK if everything looks good.2. We need to add the source for the DLL to the project. From theProject menu, select “Add to Project” and then “Files.” Navigateto the source directory and select dlltest.c and dlltest.h (you can selectboth by holding down the shift key when you click on them). VizStudiohas now added theses files to the project and organized them somewhat.Click on the “File View” tab at the bottom of the screen. Then clickon the + symbol beside “testDLL files” to view the files in this project.Expanding the Source Files folder will reveal testdll.c, while testdll.h1www.cs.cornell.edu/Course/cs404/2002sp1is in the “Header Files” folder. These folders are just VizStudio’s wayof organizing your code–they don’t refer to actual folders (the filesare still in the source directory). Double click on dlltest.h. How isPrintArray defined? Compare this to the prototypes for Error andRandomLocalFunction.3. To build the DLL, select “Build testdll.dll” from the “Build” menu.This will compile the code and create several files in the Debug directoryunder testDLL. Look at the contents of the Debug directory. The threeinteresting files are the DLL (testDLL.dll), the list of exported functions(testDLL.exp), and the library (testDLL.lib). In windows terminology,a DLL is like a shared-object library (.so file) on UNIX, while a regularlibrary (.lib file) is a static library (.a file). Why do you think we haveboth a .lib file and a DLL?4. We now need to build our main program. Create a new VizStudioproject, but this time, select “Win32 console application.” I created myproject in DLLtest and called it “TestIt.” You will then be asked whatkind of console app you want to create; choose and empty one. Addthe source file testit.c. Take a look at this file. It is a simple programwhose only purpose is to test our DLL. It asks for a file name, createsa length 10 array, fills it with numbers, and then calls PrintArray (inthe DLL) to print it out. Try building this program by selecting “BuildTestIt” from the Build menu. What happens?5. Although the file compiles, it doesn’t link correctly because we haven’ttold it where to find the object code for PrintArray. To fix this, we needto do the Windows-equivalent of augmenting our library search pathwith the -L flag and linking to testDLL.lib. Select “Settings” fromthe “Project” menu. This will bring up a window with several tabsand menus. The settings panel is how you control how your projectgets built–it is a lot like setting compiler flags in UNIX. Since we’rehaving trouble linking, click on the “Link” tab. Select “Input” from the“Category” menu. The fields in the window will change. In particular,a field called “Additional library path” will appear, se cond from thebottom. This is like the input for -L. Unfortunately, Microsoft didn’tbother to make this easy by providing a browse option, you must enterthe path by hand. I entered:S:\DLLtest\testDLL\Debug2We then need to add “\t.lib” to the list of “Object/library modules”near the top. Just type it in at the end of the list. Click OK and trybuilding again. Let me know if it doesn’t work.6. We’re now ready to run our program. Our program is designed to runfrom a console. Open up the Command Prompt application, it is foundunder the Start menu, in the Accessories folder. An intimidating blackwindow will open up. Type “S:” at the prompt to change to the Sdrive. Then cd to DLLtest\TestIt\Debug, where TestIt.exe is. To runthe program, type TestIt at the c ommand prompt. What happens?7. Even though we linked to the DLL (or its library), we haven’t told thesystem where to find testDLL.dll. To do this, we need to set a systemvariable called PATH to include the directory containing our DLL. Tosee the current value of PATH, type PATH on the command line. Toadd DLLtest\testDLL\Debug to your path, enter:set PATH=%PATH%;S:\DLLtest\testDLL\DebugBe careful, PATH is case sensitive, so make sure that the path youenter is exactly correct! Type PATH again to check if this directoryhas been added. Try running TestIt again. If it doesn’t work, doublecheck that you entered the path correctly.8. Now we’ll demonstrate the real utility of DLL’s. Go back to VizStu-dio and select TestDLL from the “Recent Workspaces” menu from the“File” menu. Change something inside PrintArray (I added fprintf(FIL,”%%A matlab comment line\n”); just be fore the for loop. Then, rebuildthe DLL and try running TestIt. Did your change show


View Full Document

CORNELL CS 404 - CREATING DYNAMICALLY-LINKED LIBRARIES

Download CREATING DYNAMICALLY-LINKED LIBRARIES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CREATING DYNAMICALLY-LINKED LIBRARIES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CREATING DYNAMICALLY-LINKED LIBRARIES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?