Introduction to C & C++ Lecture 10 – library JJCAO.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

Chapter 11 Introduction to Programming in C
CSE 105 Structured Programming Language (C)
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
SCIP Optimization Suite
CSE 303 Lecture 16 Multi-file (larger) programs
Chapter 3 Loaders and Linkers
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
GridRPC Sources / Credits: IRISA/IFSIC IRISA/INRIA Thierry Priol et. al papers.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Building User Libraries.
Guide To UNIX Using Linux Third Edition
Chapter 10 Application Development. Chapter Goals Describe the application development process and the role of methodologies, models and tools Compare.
AE6382 Extending MATLAB. AE6382 Using MATLAB MATLAB can be used as a mathematical scripting language (.m files) Stand-alone MATLAB applications –MATLAB.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Programming Languages and Paradigms Object-Oriented Programming.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 © 2012 The MathWorks, Inc. Speeding up MATLAB Applications.
Using Visual Studio 2013 An Integrated Development Environment (IDE)
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
CSCI 171 Presentation 1. Computer Software System Software –Operating systems –Utility programs –Language compilers Application Software.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Mex. Introduction to MEX MEX = Matlab EXecutable – Dynamically Linked Libraries – Used like a.m function – Written in C (or Fortran)
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Compiled Matlab on Condor: a recipe 30 th October 2007 Clare Giacomantonio.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Scientific Computing Division A tutorial Introduction to Fortran Siddhartha Ghosh Consulting Services Group.
1 ENERGY 211 / CME 211 Lecture 26 November 19, 2008.
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Computer Programming I Hour 2 - Writing Your First C Program.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 4 – August 30, 2001.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
What Is Java? According to Sun in a white paper: Java: A simple, object-oriented, network-savvy, interpreted, robust, secure, architecture-neutral, portable,
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
ITC Research Computing Support Using Matlab Effectively By: Ed Hall Research Computing Support Center Phone: Φ Fax:
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Introduction to C and CMex E177 April 1, Copyright , Andy Packard. This work is licensed under the.
FOUNDATION IN INFORMATION TECHNOLOGY (CS-T-101) TOPIC : INFORMATION SYSTEM – SOFTWARE.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
1 How to Install OpenGL u Software running under Microsoft Windows makes extensive use of "dynamic link libraries." A dynamic link library (DLL) is a set.
Program Libraries 1. What is a program library? A library is a collection of implementations of behavior, written in terms of a language, that has a well-defined.
Introduction to CMex E177 April 25, Copyright 2005, Andy Packard. This work is licensed under the Creative.
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
Chapter 9: Coupling & Cohesion Omar Meqdadi SE 273 Lecture 9 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Pyragen A PYTHON WRAPPER GENERATOR TO APPLICATION CORE LIBRARIES Fernando PEREIRA, Christian THEIS - HSE/RP EDMS tech note:
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
Topic 2: Hardware and Software
Chapter 14 Windows Programming with the Microsoft Foundation Classes
Computer Terms Review from what language did C++ originate?
APPENDIX a WRITING SUBROUTINES IN C
Topics Introduction Hardware and Software How Computers Store Data
Microprocessor and Assembly Language
TCL command in C, a simple example Nguyen Truong – GCS VN Aug 5, 2004
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Computer Science 210 Computer Organization
Chapter 11 Introduction to Programming in C
Computer Terms Review from what language did C++ originate?
The Role of Command Line Compiler (csc.exe)
ENERGY 211 / CME 211 Lecture 28 December 1, 2008.
Understanding DLLs and headers, and libs… Jeff Chastine.
ENERGY 211 / CME 211 Lecture 29 December 3, 2008.
Presentation transcript:

Introduction to C & C++ Lecture 10 – library JJCAO

Content Static lib Dynamic lib Mex Open source libraries

Library A library is a package of code that is meant to be reused by many programs. Typically, a C++ library comes in two pieces: 1) A header file that defines the functionality the library is exposing (offering) to the programs using it. 2) A precompiled binary that contains the implementation of that functionality pre-compiled into machine language. Note: Some libraries may be split into multiple files and/or have multiple header files.

Libraries are precompiled for several reasons First, since libraries rarely change, they do not need to be recompiled often. It would be a waste of time to recompile the library every time you wrote a program that used them. Second, because precompiled objects are in machine language, it prevents people from accessing or changing the source code, which is important to businesses or people who don’t want to make their source code available for intellectual property reasons.

Static & dynamic library A static library (archive) consists of routines that are compiled and linked directly into your program. When you compile a program that uses a static library, all the functionality of the static library becomes part of your executable. –.lib extension for windows –.a extension for Linux A dynamic library (shared library) consists of routines that are loaded into your application at run time. When you compile a program that uses a dynamic library, the library does not become part of your executable — it remains as a separate unit. –.dll extension for windows –.so extension for Linux

Create a static lib 1. Win32 console application

2. Application settings

Call a static lib Create a project, such as win32 console app Include header files Call functions in the lib & Tell your program where to locate the lib

Create a dll 1. Win32 console application 2. Application settings

3. After the project is created, it defined MYDLL_EXPORTS automatically. How to use it?

#ifdef MYDLL_EXPORTS #define MY_DLL_API __declspec(dllexport) #else #define MY_DLL_API __declspec(dllimport) #endif MY_DLL_API void print_dynamic(); class MY_DLL_API PointArray { private: std::vector pts; int size; public: PointArray(){} void push_back( const Point &p); };

Call a dll Create a project, such as win32 console app Include header files Call functions in the dll & Tell your program where to locate the lib

MEX-files 1.Interface to external programs written in C and Fortran 2.Dynamically linked subroutines behaving like M-files 3.But platform-specific (dll for wondows) 4.Applications: ①Pre-existing C and Fortran programs can be called without having to be rewritten ②Bottleneck computations, e.g., for-loops, can be recoded in C or Fortran for efficiency

Matlab Data Only mxArray: – Its type – Its dimensions – The data associated with this array – If numeric, whether the variable is real or complex – If sparse, its indices and nonzero maximum elements – If a structure or object, the number of fields and field names

Build Mex-file Supported compilersoptions files Lcc C Compiler (bundled)lccopts.bat Microsoft Visual C++msvc90opts.bat System ANSI Compilermexopts.sh GCCgccopts.sh Compile: mex filename -f Configure: mex–setup Test your configure – mex yprime.c – yprime(1,1:4) C:\Program Files\MATLAB\R2009a\bin\win32\mex opts C:\Program Files\MATLAB\R2009a\extern\examples\mex\ yprime.c

Structure of C Mex-File A C MEX-file gateway routine: void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* more C code... */ } Mex-file = Gateway routine + computational routine

Two simple examples – Scalar_times.c – Matrix_times.c Important functions: – mexErrMsgTxt("Two input arguments required."); – mxGetPr – mxCreate* functions, like mxCreateDoubleMatrix, mxCreateSparse, or mxCreateStringmxCreateDoubleMatrix mxCreateSparsemxCreateString

Advanced Topics Help – Use m-file sharing same name Link multiple files – mex circle.c square.obj rectangle.c shapes.lib – Output: circle. Mexw32 Memory management Automatic Cleanup of Temporary Arrays – You are more efficient than the automatic mechanism. – Persistent Arrays – …

Team work SVN

Competition ACM/ICPC