arm-linux-gcc using

1. Compile the C file, an executable file generated elf source h1.c

#include <stdio.h> void hellofirst(void)

{

printf("The first hello! \n");

}

 

h2.c source file

#include <stdio.h> void hellosecond(void)

{

printf("The second hello! \n");

}

 

hello.c source file

#include  <stdio.h> void hellosecond(void); void hellofirst(void);

 

int main(int argc, char *argv[])

{

hellofirst(); hellosecond(); return(0);

}

Compile more than three files, there are several ways:

method 1:

[arm@localhost gcc]#arm­linux­gcc ­c h1.c [arm@localhost gcc]#arm­linux­gcc ­c h2.c

[arm@localhost gcc]#arm­linux­gcc ­o hello hello.c h1.o h2.o

Method 2:

[arm@localhost gcc]#arm­linux­gcc ­c h1.c h2.c [arm@localhost gcc]#arm­linux­gcc ­o hello hello.c h1.o h2.o 方法 3:

[arm@localhost gcc]#arm­linux­gcc ­c ­o h1.o h1.c

 

[arm@localhost gcc]#arm­linux­gcc ­c ­o h1.o h1.c [arm@localhost gcc]#arm­linux­gcc ­o hello hello.c h1.o h2.o 方法 4:

[arm@localhost gcc]#arm­linux­gcc ­o hello hello.c h1.c h2.c

c: compile only unconnected.

o: compiling and connected.

 

2. When generating a preprocessed file depends upon a result of the macro in the source file, is appropriate.

[arm@localhost gcc]#arm­linux­gcc ­E h1.i h1.c

E: generating a preprocessed file.

 

3. Generate a dynamic library

DLL at runtime libraries needed.

[arm@localhost gcc]#arm­linux­gcc ­c ­fpic h1.c h2.c [arm@localhost gcc]#arm­linux­gcc ­shared h1.o h2.o ­o hello.so [arm@localhost gcc]#arm­linux­gcc ­o hello hello.c hello.so

Hello.so copied to the in / lib target board, copying the executable file in / tmp target board, the target board running hello.

#/tmp/hello

Or copy hello.so hello together and to the / tmp target, and set the environment variable LD_LIBRARY_PATH

#export LD_LIBRARY_PATH =/tmp:$LD_LIBRARY_PATH

#/tmp/hello

Guess you like

Origin www.cnblogs.com/fanweisheng/p/11105582.html