Beginning Linux-1. Getting started

Programming Linux

A vast range of programming languages are available for Linux systems, and many of them are free and available on CD-ROM collections or from FTP archive sites on the Internet. Here’s a partial list of programming languages available to the Linux programmer:

adaCC++
EiffelForthFortran
IconJavaJavaScript
LispModula 2Modula 3
OberonObjective CPascal
PerlPostScriptProlog
PythonRubySmalltalk
PHPTcl/TkBourne Shell

we mainly concentrate on C. We direct our attention mostly toward exploring the Linux programming interfaces from the perspective of the C programmer, and we assume knowledge of the C programming language.

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; they correspond to Windows .exe files. Scripts are collections of instructions for another program, an interpreter, to follow. These correspond to Windows .bat or .cmd files, or interpreted BASIC programs.

The shell finds the programs you ask for by name by searching for a file with the same name in a given set of directories. The directories to search are stored in a shell variable, PATH. And some standard places where
system programs are stored include:

  • /bin: Binaries, programs used in booting the system
  • /usr/bin: User binaries, standard programs available to users
  • /usr/local/bin: Local binaries, programs specific to an installation

Text Editors

The text editors we usually used include: vim, emacs and so on.

The C and C++ Compiler

On most Linux distributions, the gcc and g++ compilers are used for C programs and C++ programs.

program.c is the source file of the program, program is the name you give to the executable program.
gcc -o program program.c

gcc -I/your/include/path program.c direct the compiler to look in the directory /your/include/path, as well as the standard places.

grep text-pattern search-files searches the files search-files for the string text-pattern.

Library Files

Libraries are collections of precompiled functions that have been written to be reusable. Typically, they consist of sets of related functions to perform a common task.
Standard system libraries are usually stored in /lib and /usr/lib. The C compiler (or more exactly, the linker) needs to be told which libraries to search, because by default it searches only the standard C library.

  • .a for traditional, static libraries
  • .so for shared libraries
    The commands used to link to a library libm.a is :
    gcc -o program program.c /your/file/path/libm.a
    gcc -o program program.c -lm (The library is in the standard library directories.)
    gcc -o program program.c -L/your/lib/path -lm

You can see which shared libraries are required by a program by running the utility ldd.

Getting Help

The command man and info is used to search docs usually.

Summary

In this introductory chapter, we’ve looked at Linux programming and the things Linux holds in common with proprietary UNIX systems. We’ve noted the wide variety of programming systems available to UNIX developers. We’ve also presented a simple program and library to demonstrate the basic C tools, comparing them with their Windows equivalents.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值