简体   繁体   中英

Can Gcc build a executable program?

All, Forgive me I am familiar with the C program for the Android/Linux platform. Now I am trying to use the Sourcery G++ Lite Edition for ARM to build my sample C program and deploy it to the Linux of the Android platform. Below is the instructions what I follow. So far it works fine. But I have something I didn't understand well. please review it . thanks.

The Source code is a hello world program.

#include <stdio.h>
int main(int argc,char * argv[])
{
  printf("Hello, Android!\n");
  return 0;
}

In the development machine command console. run the following commands line.

arm-none-linux-gnueabi-gcc hello.c -static -o hellostatic
adb push hellostatic /data/test
adb shell
cd /data/test
.hellostatic

Hello, Android!

So here is my question.

Can gcc build a executable file from ac source code file? Seems It doesn't need link tool. Is it right? thanks.

Can gcc build a executable file from ac source code file?

yes, of course.

Seems It doesn't need link tool?

no, I extract the following sentences from gcc manual, GCC is capable of preprocessing and compiling several files either into several assembler input files, or into one assembler input file; then each assembler input file produces an object file, and linking combines all the object files (those newly compiled, and those specified as input) into an executable file.

At default gcc will do complie and link operation, unless you type particular options such like:

gcc -c file.c

this will just compile file.c to file.o or:

gcc -o file file.c

this will complie file.c to file.o and also link it to make a executable file finally.

Although yanchong had already gave the nice answer , I also found a good read from here . I think it will help to understand the concepts of Compile, Link and Build . Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM