The build process + misc

Slides:



Advertisements
Similar presentations
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Advertisements

Run-time Environment and Program Organization
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 1, Lab.
Software Development and Software Loading in Embedded Systems.
CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
C O M P U T E R G R A P H I C S Jie chen Computer graphic -- OpenGL Howto.
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
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.
Topic 1Topic 2Topic 3Topic 4Topic
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Lecture 11 Dynamic link libraries. Differences between static libraries and DLLs In static library code is added to the executable. In DLL, the code is.
CRT State Stuff Dana Robinson The HDF Group. In the next slide, I show a single executable linked to three dlls. Two dlls and the executable were built.
Topic 2d High-Level languages and Systems Software
C/C++ Programming Environment
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
Writing a Run Time DLL The application loads the DLL using LoadLibrary() or LoadLibraryEx(). The standard search sequence is used by the operating system.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
Lecture 01a: C++ review Topics: Setting up projects, main program Memory Diagrams Variables / Types (some of) the many-types-of-const's Input / Output.
Lecture 01d: C++ review Topics: functions scope / lifetime preprocessor directives header files C structures ("simple classes")
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
Lecture 3 Translation.
Introduction to Operating Systems
INF230 Basics in C# Programming
Process concept.
Intro to ETEC Java.
Tools of the Trade
High-level languages + Python
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
Objectives Identify the built-in data types in C++
Linking & Loading.
Computer Programming Lecturer: Ir Dr Frank H.F. LEUNG
Run-time organization
Software Development with uMPS
CS-3013 Operating Systems C-term 2008
An Embedded Software Primer
Java Virtual Machine Complete subject details are available at:
Topic 2e High-Level languages and Systems Software
Advanced Programming Behnam Hatami Fall 2017.
and Executing Programs
CSC 253 Lecture 8.
CMSC 341 Prof. Michael Neary
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Chapter 9 :: Subroutines and Control Abstraction
Compiler Construction
Introduction to Operating Systems
CSC 253 Lecture 8.
Computer Organization & Compilation Process
Code Generation.
Memory Allocation CS 217.
CMP 131 Introduction to Computer Programming
Linking & Loading CS-502 Operating Systems
Programming Languages
(Computer fundamental Lab)
Introduction to Computer Systems
CS510 Operating System Foundations
10/6: Lecture Topics C Brainteaser More on Procedure Call
Linking & Loading CS-502 Operating Systems
CSE 153 Design of Operating Systems Winter 2019
Computer Organization & Compilation Process
COMP755 Advanced Operating Systems
Cmake + Physics Lecture 2.
Overview of System Development for Windows CE.NET
Hello World Program In Visual Studio and Debugging
SPL – PS1 Introduction to C++.
IS 135 Business Programming
Presentation transcript:

The build process + misc Lecture 3

Compiling / linking (the file extensions are windows, general idea is for all OS’s) When you build a project, there are several sub-steps Pre-processor expansions Compiling Linking Debug-file (pdb) creation When the user runs the executable [in debugger] Dynamic linking OS process creation [Debug Triggers]

Step1: Pre-processor expansion All #xyz sections (in .cpp) are textually replaced // foo.h #define AMT 5.0f #define min(a, b) (a) < (b) ? (a) : (b) void foo(int a, float b); class Test { }; // foo.cpp #include “foo.h” bool foo(int x, float y) { if (x < y) return min(x, AMT); else return min(y, AMT); } Pre-processor // foo.cpp // foo.h void foo(int a, float b); class Test {}; bool foo(int x, float y) { if (x < y) return (x) < (5.0f) ? (x) : (5.0f); else return (y) < (5.0f) ? (y) : (5.0f); }

Step1b: Pre-compiled Headers The process of evaluating headers… especially if a header includes another header …can take a long time. All C/C++ compilers have an option to enable pre-compiled headers All the header evaluations are done once and stored in a massive pch file / database. Anytime a full-rebuild is initiated or a header changes, the pch file is rebuilt. So…we want to include non-changing headers in the pch and do everything else as normal.

step1b, cont. Steps in visual studio (make sure to do this for Debug and Release) ProjectProperties => C/C++ => PreCompiled Headers Precompiled Header => Use (/Yu) Create a stdafx.h and put all non-changing headers in it: #include <string> #include <SDL.h> // etc. Create stdafx.cpp #include <stdafx.h> // (and this is all!) Right-click on stdafx.cpp in Solution Explorer and pick Properties Change C/C++ => PreCompiled Headers => Precompiled Header to Create (/Yc) For every .h and .cpp file you create from here on, include <stdafx.h> as the first thing. Else you’ll get some cryptic error message.

Step2: Compiler Every .cpp (there are no longer .h files!) in the project is converted to machine code (.obj) foo.obj* // foo.cpp // foo.h void foo(int a, float b); class Test {}; bool foo(int x, float y) { if (x < y) return (x) < (5.0f) ? (x) : (5.0f); else return (y) < (5.0f) ? (y) : (5.0f); } LDX INTIM BNE Hold STX WSYNC STX VBLANK STX REFP0 STX REFP1 INX STX VDELP0 STX VDELP1 LDX #$03 STX NUSIZ0 STX NUSIZ1 STX HMCLR NOP ... Compiler * Technically, this is a disassembly of what would look like binary gibberish

Step3: Linker The linker combines… …into a single .exe All machine code in .obj files from our project. All statically-linked .lib files also machine code, but not from our project. e.g. SDL.lib All stubs for dynamically-linked code. These are also .lib files (usually small by comparison) But…they contain code which requests the OS load in a dll at run-time. Any other system-specific code E.g. The c-runtine (or .NET runtime) code …into a single .exe If a debug build, the following database is built in tandem: addresses in the exe and function entry-points addresses in the process for variable locations (stack and heap) [doesn’t actually store the source code!] This is all stored in a .pdb file

Step4: Runtime When the exe is launched: Discussion The OS creates a process and allocates x pages of memory All exe-relative addresses are translated to physical addresses This might happen in the CPU, depending on architecture During startup, the process may request object code to be loaded into the process memory The CPU begins executing machine code in the process And modifying variables stored in process memory Discussion Why are dll’s used in modern OS’s – why not just static lib’s? Licensing restrictions of libs (e.g. LGPL)

Pointer crash-course Several important aspects [examples on board] Pointers to primitives (and addressing) Pointer – array connection (pointer arithmetic) Pointers to structures / objects Pointer and dynamic allocation (arrays and objects)

SDL basics Simple DirectMedia Layer Very c-oriented (can still be “embedded in C++”) Used for: windowing input 2d image support (loading / blitting) sound (2d only) threading (useful before C++11) …(a few other minor things) Should be familiar from ETEC2110 We’ll later render our Ogre stuff to an SDL window. [Look at important parts of wiki together]

doxygen [Have Jason give a demo here…]

The dreaded “style talk” [Show them the thing]