1. Compile static library
(1) Examples used:
Four program files: main.c, function.h, greeting.c name.c
main.c
#include <iostream>
#include "function.h"
using namespace std;
int main()
{
cout<<"main mian"<<endl;
sayGreetings();
sayName();
return 0;
}
function.h
void sayGreetings();
void sayName();
greeting.c
#include <iostream>
using namespace std;
#include "function.h"
void sayGreetings()
{
std::cout << "hello,world" << std::endl;
}
name.c
#include <iostream>
#include "function.h"
using namespace std;
void sayName(){
cout<<"my name is aha!"<<endl;
}
(2) Compilation process
The compilation process is as shown below. The ones starting with g++ are compiled using local gcc, and the ones starting with aarch64-linux-gnu-g++ are cross-compiled into the arm version. The steps are actually the same, but the compilers used are different .
2. Compile dynamic library
The use case program file is the same as the static library. The command is as follows.
Finally, it prompts "executable file format error" because the arm architecture generated by cross compilation cannot be executed on x86. We can also view dynamic libraries or executable programs through commands. Architecture information :file liba.so 或 readelf -h liba.so