Skip to content

Commit e3741a8

Browse files
committed
feat: Uinx/Linux 下使用gcc/g++ 制作.so和.a调用
1 parent 12047a9 commit e3741a8

File tree

22 files changed

+319
-0
lines changed

22 files changed

+319
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// ExAdd.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <stdio.h>
10+
11+
double add(double a, double b)
12+
{
13+
return a + b;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// ExDiv.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <stdio.h>
10+
11+
double div(double a, double b)
12+
{
13+
return a * 1.0 / b;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// ExMul.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <stdio.h>
10+
11+
double mul(double a, double b)
12+
{
13+
return a * b;
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// ExSub.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <stdio.h>
10+
11+
double sub(double a, double b)
12+
{
13+
return a - b;
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ExHeader.h
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#ifndef ExHeader_h
10+
#define ExHeader_h
11+
12+
double add(double a, double b);
13+
double sub(double a, double b);
14+
double mul(double a, double b);
15+
double div(double a, double b);
16+
17+
#endif /* ExHeader_h */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// main.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
using namespace std;
11+
#include "ExHeader.h"
12+
13+
int main(int argc, const char * argv[]) {
14+
// insert code here...
15+
double a = 12;
16+
double b = 2;
17+
18+
double valAdd = add(a, b);
19+
double valSub = sub(a, b);
20+
double valMul = mul(a, b);
21+
double valDiv = div(a, b);
22+
23+
cout<<"[显示结果"
24+
<<" a:"<<a
25+
<<" b:"<<b
26+
<<" ]\n"
27+
<<" valAdd:"<<valAdd
28+
<<" valSub:"<<valSub
29+
<<" valMul:"<<valMul
30+
<<" valDiv:"<<valDiv
31+
<<endl;
32+
33+
return 0;
34+
}
9.43 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExAdd.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double add(double a, double b)
10+
{
11+
return a + b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExDiv.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double div(double a, double b)
10+
{
11+
return a * 1.0 / b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExMul.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double mul(double a, double b)
10+
{
11+
return a * b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExSub.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double sub(double a, double b)
10+
{
11+
return a - b;
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ExHeader.h
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#ifndef ExHeader_h
10+
#define ExHeader_h
11+
12+
double add(double a, double b);
13+
double sub(double a, double b);
14+
double mul(double a, double b);
15+
double div(double a, double b);
16+
17+
#endif /* ExHeader_h */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// main.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
using namespace std;
11+
#include "ExHeader.h"
12+
13+
int main(int argc, const char * argv[]) {
14+
// insert code here...
15+
double a = 12;
16+
double b = 2;
17+
18+
double valAdd = add(a, b);
19+
double valSub = sub(a, b);
20+
double valMul = mul(a, b);
21+
double valDiv = div(a, b);
22+
23+
cout<<"[显示结果"
24+
<<" a:"<<a
25+
<<" b:"<<b
26+
<<" ]\n"
27+
<<" valAdd:"<<valAdd
28+
<<" valSub:"<<valSub
29+
<<" valMul:"<<valMul
30+
<<" valDiv:"<<valDiv
31+
<<endl;
32+
33+
return 0;
34+
}
16.9 KB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExAdd.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double add(double a, double b)
10+
{
11+
return a + b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExDiv.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double div(double a, double b)
10+
{
11+
return a * 1.0 / b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExMul.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double mul(double a, double b)
10+
{
11+
return a * b;
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// ExSub.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
double sub(double a, double b)
10+
{
11+
return a - b;
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// ExHeader.h
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#ifndef ExHeader_h
10+
#define ExHeader_h
11+
12+
double add(double a, double b);
13+
double sub(double a, double b);
14+
double mul(double a, double b);
15+
double div(double a, double b);
16+
17+
#endif /* ExHeader_h */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// main.cpp
3+
// test
4+
//
5+
// Created by muli on 2020/3/2.
6+
// Copyright © 2020 muli. All rights reserved.
7+
//
8+
9+
#include <iostream>
10+
using namespace std;
11+
#include "ExHeader.h"
12+
13+
int main(int argc, const char * argv[]) {
14+
// insert code here...
15+
double a = 12;
16+
double b = 2;
17+
18+
double valAdd = add(a, b);
19+
double valSub = sub(a, b);
20+
double valMul = mul(a, b);
21+
double valDiv = div(a, b);
22+
23+
cout<<"[显示结果"
24+
<<" a:"<<a
25+
<<" b:"<<b
26+
<<" ]\n"
27+
<<" valAdd:"<<valAdd
28+
<<" valSub:"<<valSub
29+
<<" valMul:"<<valMul
30+
<<" valDiv:"<<valDiv
31+
<<endl;
32+
33+
return 0;
34+
}
9.46 KB
Binary file not shown.

unix_linux_04_make_so_a/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Uinx / Linux Example
2+
3+
------
4+
5+
**💻:** `MacOS 10.14.6 (18G103)` 📎 `gcc/g++ 9.2.0`
6+
7+
**💻:** `UOS20 (即deepin20)` 📎 `gcc/g++ 8.3.0`
8+
9+
10+
11+
- **04_01_a:** 制作静态库.a和调用 [mac]
12+
- **04_02_so:** 制作动态库.so和调用 [uos]
13+
- **04_03_so:** 制作动态库.so和调用 [mac]
14+

0 commit comments

Comments
 (0)