Beginning Linux Programming - Chapter 1: Getting Started

Unix, Linux, and GNU

  • Unix
    • The UNIX operating system was originally developed at Bell Laboratories, once part of the telecommunication giant AT&T
    • History
      • Unix is a trademark administered by The Open Group, and it refers to a computer operating system that conforms to a particular specification. This specification, known as The Single UNIX Specification, defines the names of, interfaces to, and behaviors of all mandatory UNIX operating system functions
      • The above specification is largely a superset of an earlier series of specifications, POSIX (Portable Operating System Interface) specifications, developed by the IEEE (Institute of Electrical and Electronic Engineers)
      • In the past, compatibility among different UNIX systems has been a problem
    • Philosophy
      • Simplicity - KISS - "Keep It Small and Simple"
      • Focus - it's often better to make a propgram perform one taks well than to throw in every feature along with the kitchen sink
      • Reusable Components - Make the core of your application available as a library
      • Filters - Many UNIX applications can transfrom their input and produce output, which can be combined with other UNIX programs
      • Open File Formats - The more successful and popular UNIX programs use configuration files and data files that are plain ASCII text or XML
      • Flexibility - avoid unnecessary restrictions
  • Linux
    • Linux is a freely distributed implementation of a UNIX-like kernel, the low-level core of an operating system
    • The intention is that the Linux kernel will not incorporate proprietary code but will contain nothing but freely distributable code
    • Linux distributions
      • Linux is actually just a kernel
      • You can obtain the sources for the kernel to compile and install it on a machien and then obtain and install many other freely distributed software programs to make a complete Linux installation
      • These installations are usually refered to as Linux systems, because they consist of much more htan just the kernel
  • The GNU Project and the Free Software Foundation
    • The Linux community supports the concept of free software, that is, sofware that is free from restrictions, subject to the GNU General Public License. Alghotugh there may be a cost involved in obtaining the software, it can thereafter be use in any way desired and is usually distributed in source form
    • The Free Software Foundation was set up by Richard Stallman, the author of GNU Emacs
    • Several examples of software from the GNU Project distributed under GPL
      • GCC: The GNU Compiler Collection, containing the GNU C compiler
      • G++: A C++ compiler
      • GDB: A source code-level debugger
      • GNU make: A version of UNIX make
      • Bison: A parser generator compatible with UNIX yacc
      • bash: A command shell

Progams and programming languages for Linux

  • Linux Programs
    • Linux applications are represented by two special types of files: executables and scripts. Executable files are programs that can be run directly by the computer. Scripts are collections of instructions for antoher program, an interpreter, to follow. These correspond to Windows .bat or .cmd files, or interpreted BASIC programs
    • Linux doesn't require executables or scripts to ahve a specific filename or any extension whatsoever
    • When you log in to a Linux system, you interact with a shell program that runs programs in the same way that hte Windows command prompt does. The directories to serach are stored in a shell variable, PATH
      • /bin: Binaries, prgrams used in booting the system
      • /usr/bin: User binaries, standard programs available to users
      • /usr/local/bin: Local binaries, programs specific to an installation
      • An administrator's login, such as root, may use a PATH varaible that includes directories where system administration programs are kept, such as /sbin and /usr/sbin
      • Optional operating system components and third-party applications may be installed in subdirectories of /opt
      • Linux, like UNIX, uses the colon character to seperate entries in the PATH variable
        • /usr/local/bin:/bin:/usr/bin:.:/home/neil/bin:/usr/X11R6/bin

           

      • Linux uses a forward slash (/) = to separate directory names in a filename

  • The C Compiler

    • On POSIX-compliant systems, the C compiler is called c89. Historically, the C compiler was simply called cc

  • Your First Linux C program

    • #include <stdio.h>
      #include <stdlib.h>
      
      int main()
      {
      	printf("Hello World\n");
      	exit(0);
      }
      
      /* to run the program
       gcc -o hello hello.c
       ./hello
      */

       

    • How it works

      • You invoked the GNU C compiler that translated the C source code into an executable file called hello

      • If PATH doesn't include a reference to your home directory, the shell won't be able to find shell 

      • If you forget the -o name option that tells the compiler where to place the executable, the compiler will place the program in a file called a.out

How to locate development resources

  • Applications
    • /usr/bin: applications supplied by the system for general use, including program development
    • /usr/local/bin or /opt: applications added by system administrators for a specific host computer or local network
    • Administrators favor /opt and /usr/local, because they keep vendor-supplied files and later additions separate from the applications upplied by the system
  • Header Files
    • For programming in C and other languages, you need header files to provide definitions of constants and declarations for system and library function calls
  • Library Files
    • Standard system libaries are sually stored in /lib and /usr/lib
    • Names
      • A library filename always starts with lib. The last part of the name starts with a dot, and specifies the type of the library
        • .a for traditional, static libraries
        • .so for shared libraries

Static and shared libraries

  • Static libraries
    • Static libraries, also known as archives, conventionally have names that end with .a
  • Create a static librariy
    • Suppose we have freq.c. and bill.c such that
      • #include <stdio.h>
        
        void fred(int arg)
        {
        	printf("fred: we passed %d\n", arg);
        }
        
        #include <stdio.h>
        
        void bill(char *arg)
        {
        	printf("bill: we passed %s\n", arg);
        }

         

      • We can compile these functions individually to produce object files ready for inclusion into a library. Doing this by invokin gthe C compiler with the -c option, which prevents the compiler from trying to create a complete program

      • gcc -c bill.c fred.c 
        ls *.o
        
        /* output
        
        bill.o fred.o
        
        */

         

      • It is a good ideato create a header file for your library. This will declare the functions in your library and should be included by all applications that want ot sue your library

      • void bill(char *);
        void freq(int);

        .

      • The calling program

      • #include <stdlib.h>
        #include "lib.h"
        
        int main()
        {
        	bill("Hello World");
        	exit(0);
        }

         

      • Compile the program and test it. For now, specify the object files explicity to the compiler, asking it to compile your file and link it with the previously compiled object module bill.o

      • gcc -c program.c
        gcc -o program program.o bill.o
        ./program
        
        /* output
        bill: we passed Hello World
        */

         

      • Create and use a library. Use the ar program to create th earchive and add your object files to it. The program is called ar because it creates archives, or collections, of individual files place together in one large file

      • ar crv libfoo.a bill.o fred.o
        
        /* output 
        a - bill.o
        a - fred.o
        */

         

      • The library is created and the two object files added. To use the library successfully, some systems, notably those derived from Berkeley UNIX, require that a table of contents be created for the library. Do this with the ranlib command

      • ranlib libfoo.a

         

      • Your library is now ready to use. You can add to the list of files to be used by the compiler to crate your program like this

      • gcc -o program program.o libfoo.a
        ./program
        
        /* output
        bill: we passed Hello World
        */

         

    • Shared Libraries

      • One disadvantage of static libraries is that when you run many applications at the same time and they all use functions from the same library, you may end up with many copies of hte same functions in memory and indeed many copies in the program files themselves. This can consume a large amount of valuable memory and disk space

      • Shared libraries are stored in the same places as static libraries, but shared libraries have a different filename suffix. On a typicl Linux system, the shared version of the standard math library is /lib/libm.so

      • When a program uses a shared library, it is linked in such a way that it doesn't contain function code itself, but references to shared code that will be made available at run time. When the resulting program is loaded into memory to be executed, the function references are resolved and calls are made to the shared library, which will be loaded into memory if needed

      • For Linux systems, hte program that takes care of loading shared libraries and resolving client program function references is called ld.so

      • You can see which shared libraries are requires by a program by running the utility ldd

Getting Help

  • man 
    • man gcc
  • info
    • info gcc
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Beginning iOS AR Game Development:Developing Augmented Reality Apps with Unity and C# by Allan Fowler-November 24, 2018 Beginning iOS AR Game Development: Developing Augmented Reality Apps with Unity and C# by Allan Fowler Apress English 2018-11-19 244 pages Details Title: Beginning iOS AR Game Development: Developing Augmented Reality Apps with Unity and C# Author: Allan Fowler Length: 244 pages Edition: 1st ed. Language: English Publisher: Apress Publication Date: 2018-11-19 ISBN-10: 1484236173 ISBN-13: 9781484236178 Description Create a fully featured application that’s both sophisticated and engaging. This book provides a detailed guide in developing augmented reality games that can take advantage of the advanced capabilities of new iOS devices and code while also offering compatibility with still supported legacy devices. No programming experience is necessary as this book begins on the ground floor with basic programming concepts in Unity and builds to incorporating input from the real world to create interactive realities. You’ll learn to program with the Unity 2017 development platform using C#. Recent announcements of increased AR capabilities on the latest iPhones and iPads show a clear dedication on Apple’s part to this emerging market of immersive games and apps. Unity 2017 is the latest version of this industry leading development platform and C# is a ubiquitous programming language perfect for any programmer to begin with. Using the latest development technologies, Beginning iOS AR Game Development will show you how to program games that interact directly with the real world environment around the user for creative fantastic augmented reality experiences. What You'll Learn Download assets from the Unity store Create a scene in Unity 2017 Use physics and controls on mobile devices Who This Book Is For Beginner programmers and/or people new to developing games using Unity. It also serves as a great introduction to developing AR games and educators teaching the subject at high school or higher levels. Table of Contents Chapter 1: Introduction Chapter 2: Getting Started Chapter 3: The Unity ARKit Chapter 4: Hit Testing and Lighting Chapter 5: Making AR Games Chapter 6: Introducing Touch Chapter 7: Adding Plane Detection and Point Clouds Chapter 8: Final Steps
xv Contents Graphical Debugging Tools 299 DDD 299 Eclipse 302 Kernel Debugging 305 Don’t Panic! 306 Making Sense of an oops 307 Using UML for Debugging 309 An Anecdotal Word 312 A Note about In-Kernel Debuggers 313 Summary 313 Chapter 11: The GNOME Developer Platform 315 GNOME Libraries 316 Glib 316 GObject 316 Cairo 316 GDK 317 Pango 317 GTK+ 317 libglade 318 GConf 318 GStreamer 318 Building a Music Player 319 Requirements 319 Getting Started: The Main Window 319 Building the GUI 321 Summary 340 Chapter 12: The FreeDesktop Project 341 D-BUS: The Desktop Bus 341 What Is D-Bus? 342 Under D-Hood of D-Bus 342 D-Bus Methods 346 Hardware Abstraction Layer 350 Making Hardware Just Work 350 Hal Device Objects 353 The Network Manager 358 Other Freedesktop Projects 360 Summary 360 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xv xvi Contents Chapter 13: Graphics and Audio 361 Linux and Graphics 361 X Windows 362 Open Graphics Library 364 OpenGL Utilities Toolkit 365 Simple Directmedia Layer 365 Writing OpenGL Applications 365 Downloading and Installing 366 Programming Environment 367 Using the GLUT Library 368 Writing SDL Applications 382 Downloading and Installing 382 Programming Environment 383 Using the SDL Library 383 Summary 394 Chapter 14: LAMP 395 What Is LAMP? 395 Apache 396 MySQL 396 PHP 397 The Rebel Platform 397 Evaluating the LAMP Platform 397 Apache 399 Virtual Hosting 400 Installation and Configuration of PHP 5 401 Apache Basic Authentication 402 Apache and SSL 402 Integrating SSL with HTTP Authentication 403 MySQL 404 Installing MySQL 404 Configuring and Starting the Database 404 Changing the Default Password 405 The MySQL Client Interface 405 Relational Databases 405 SQL 406 The Relational Model 409 PHP 411 The PHP Language 411 Error Handling 420 Error-Handling Exceptions 421 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xvi xvii Contents Optimization Techniques 422 Installing Additional PHP Software 427 Logging 427 Parameter Handling 428 Session Handling 429 Unit Testing 430 Databases and PHP 432 PHP Frameworks 432 The DVD Library 433 Version 1: The Developer’s Nightmare 433 Version 2: Basic Application with DB-Specific Data Layer 434 Version 3: Rewriting the Data Layer,Adding Logging and Exceptions 437 Version 4: Applying a Templating Framework 441 Summary 442 Index 443 GNU 47 Acknowledgments ix Introduction xix Chapter 1: Working with Linux 1 A Brief History of Linux 2 The GNU Project 2 The Linux Kernel 3 Linux Distributions 4 Free Software vs. Open Source 4 Beginning Development 5 Choosing a Linux Distribution 6 Installing a Linux Distribution 8 Linux Community 15 Linux User Groups 15 Mailing lists 16 IRC 16 Private Communities 16 Key Differences 16 Linux Is Modular 17 Linux Is Portable 17 Linux Is Generic 17 Summary 18 Chapter 2: Toolchains 19 The Linux Development Process 19 Working with Sources 20 Configuring to the Local Environment 21 Building the Sources 22 Components of the GNU Toolchain 23 The GNU Compiler Collection 23 The GNU binutils 34 GNU Make 39 The GNU Debugger 40 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xi xii Contents The Linux Kernel and the GNU Toolchain 44 Inline Assembly 44 Attribute Tags 45 Custom Linker Scripts 45 Cross-Compilation 46 Building the GNU Toolchain 47 Summary 48 Chapter 3: Portability 49 The Need for Portability 50 The Portability of Linux 51 Layers of Abstraction 51 Linux Distributions 52 Building Packages 57 Portable Source Code 70 Internationalization 81 Hardware Portability 88 64-Bit Cleanliness 89 Endian Neutrality 89 Summary 92 Chapter 4: Software Configuration Management 93 The Need for SCM 94 Centralized vs. Decentralized Development 95 Centralized Tools 95 The Concurrent Version System 96 Subversion 104 Decentralized tools 108 Bazaar-NG 109 Linux kernel SCM (git) 112 Integrated SCM Tools 115 Eclipse 115 Summary 117 Chapter 5: Network Programming 119 Linux Socket Programming 119 Sockets 120 Network Addresses 122 Using Connection-Oriented Sockets 123 Using Connectionless Sockets 130 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xii xiii Contents Moving Data 133 Datagrams vs. Streams 133 Marking Message Boundaries 137 Using Network Programming Libraries 140 The libCurl Library 140 Using the libCurl Library 141 Summary 147 Chapter 6: Databases 149 Persistent Data Storage 149 Using a Standard File 150 Using a Database 150 The Berkeley DB Package 152 Downloading and Installing 153 Building Programs 154 Basic Data Handling 154 The PostgreSQL Database Server 165 Downloading and Installing 165 Building Programs 167 Creating an Application Database 167 Connecting to the Server 169 Executing SQL Commands 173 Using Parameters 181 Summary 184 Chapter 7: Kernel Development 185 Starting Out 185 Kernel Concepts 199 A Word of Warning 200 The Task Abstraction 200 Virtual Memory 205 Don’t Panic! 208 Kernel Hacking 208 Loadable Modules 209 Kernel Development Process 211 Git: the “Stupid Content Tracker” 212 The Linux Kernel Mailing List 213 The “mm” Development Tree 215 The Stable Kernel Team 215 LWN: Linux Weekly News 216 Summary 216 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiii xiv Contents Chapter 8: Kernel Interfaces 217 What Is an Interface? 217 Undefined Interfaces 218 External Kernel Interfaces 219 System Calls 219 The Device File Abstraction 224 Kernel Events 238 Ignoring Kernel Protections 239 Internal Kernel Interfaces 243 The Kernel API 243 The kernel ABI 244 Summary 245 Chapter 9: Linux Kernel Modules 247 How Modules Work 247 Extending the Kernel Namespace 250 No Guaranteed Module Compatibility 251 Finding Good Documentation 251 Linux Kernel Man Pages 251 Writing Linux Kernel Modules 252 Before You Begin 253 Essential Module Requirements 253 Logging 256 Exported Symbols 257 Allocating Memory 259 Locking considerations 267 Deferring work 275 Further Reading 283 Distributing Linux Kernel Modules 284 Going Upstream 284 Shipping Sources 284 Shipping Prebuilt Modules 284 Summary 285 Chapter 10: Debugging 287 Debugging Overview 287 A Word about Memory Management 288 Essential Debugging Tools 289 The GNU Debugger 289 Valgrind 298 02_776130 ftoc.qxp 2/2/07 10:13 PM Page xiv
Beginning iOS AR Game Development:Developing Augmented Reality Apps with Unity and C# by Allan Fowler-November 24, 2018 Beginning iOS AR Game Development: Developing Augmented Reality Apps with Unity and C# by Allan Fowler Apress English 2018-11-19 244 pages Details Title: Beginning iOS AR Game Development: Developing Augmented Reality Apps with Unity and C# Author: Allan Fowler Length: 244 pages Edition: 1st ed. Language: English Publisher: Apress Publication Date: 2018-11-19 ISBN-10: 1484236173 ISBN-13: 9781484236178 Description Create a fully featured application that’s both sophisticated and engaging. This book provides a detailed guide in developing augmented reality games that can take advantage of the advanced capabilities of new iOS devices and code while also offering compatibility with still supported legacy devices. No programming experience is necessary as this book begins on the ground floor with basic programming concepts in Unity and builds to incorporating input from the real world to create interactive realities. You’ll learn to program with the Unity 2017 development platform using C#. Recent announcements of increased AR capabilities on the latest iPhones and iPads show a clear dedication on Apple’s part to this emerging market of immersive games and apps. Unity 2017 is the latest version of this industry leading development platform and C# is a ubiquitous programming language perfect for any programmer to begin with. Using the latest development technologies, Beginning iOS AR Game Development will show you how to program games that interact directly with the real world environment around the user for creative fantastic augmented reality experiences. What You'll Learn Download assets from the Unity store Create a scene in Unity 2017 Use physics and controls on mobile devices Who This Book Is For Beginner programmers and/or people new to developing games using Unity. It also serves as a great introduction to developing AR games and educators teaching the subject at high school or higher levels. Table of Contents Chapter 1: Introduction Chapter 2: Getting Started Chapter 3: The Unity ARKit Chapter 4: Hit Testing and Lighting Chapter 5: Making AR Games Chapter 6: Introducing Touch Chapter 7: Adding Plane Detection and Point Clouds Chapter 8: Final Steps
iOS 7 changed everything—get up to speed! iOS 7 is a major shift in the look and feel of apps—the first major sea change since the iPhone was first introduced. For apps to blend in with the new UI, each needs a complete redesign. Beginning iOS Programming: Building and Deploying iOS Applications starts at the beginning—including an introduction to Objective C—and gives you the skills you need to get your apps up and running. Author Nick Harris has extensive experience developing for iOS and provides a solid background for teaching the building blocks of app development. Learn Objective-C and how it differs from other programming languages Turn your app idea into an actionable plan Build each feature with the help of standalone chapters Assemble your project into a real-world iOS app Throughout the book, you’ll be able to experiment with dozens of recipes from real-life scenarios, creating an app as you learn. The book’s website features download sample apps to follow along with the instruction, and sample code to illustrate ideas. Table of Contents Chapter 1: Building a Real-World iOS App: Bands Chapter 2: Introduction to Objective-C Chapter 3: Starting a New App Chapter 4: Creating a User Input Form Chapter 5: Using Table Views Chapter 6: Integrating the Camera and Photo Library in iOS Apps Chapter 7: Integrating Social Media Chapter 8: Using Web Views Chapter 9: Exploring Maps and Local Search Chapter 10: Getting Started with Web Services Chapter 11: Creating a Universal App Chapter 12: Deploying Your iOS App Appendix: Answers to Exercises Book Details Title: Beginning iOS Programming: Building and Deploying iOS Applications Author: Nick Harris Length: 336 pages Edition: 1 Language: English Publisher: Wrox Publication Date: 2014-02-24 ISBN-10: 1118841476 ISBN-13: 9781118841471

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值