Compile the. A library file used by Linux

Source: Internet
Author: User

Compile the. A library file used by Linux

The first is the source file that needs to be compiled into. A

hello.h :

#ifndef __include_hello_h__#define __include_hello_h__void HELLO (const char *name); #endif//End __include_hello_h__

hello.c

#include "stdio.h" void Hello (const char *name) {    printf ("Hello World%s\n", name);}


and A in Linux test on the platform . main.c

#include "hello.h" int main () {    Hello ("everyone");        return 0;}


Test on Linux, compile into. A files, mainly using. o Files and AR commands


1. First generate. o File:

Gcc-c hello.c

In this way, the source code directory will produce a hello.o



2. Use the AR command to create a. A file from the. o File

AR cr libhello.a hello.o

This makes it possible to generate. A files, Note that the first three bits of the . A file to be generated are preferably lib, otherwise the library may not be found at the time of the link



3, under the Linux test use

Compile the MAIN.C and let hello.a link to main

GCC main.c-l.-lhello-o main( Note that There is a. After -l)

So that in the face of the directory there is an executable program main, direct operation is the result of our request



Compile the. A library file used by Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.