Skip to content

Instantly share code, notes, and snippets.

@domiyanyue
domiyanyue / run.txt
Created May 8, 2020 22:14
use shared library
g++ main.o my_math.so -o a.out
# or
g++ main.o -L. -lmy_math -o a.out
@domiyanyue
domiyanyue / run.txt
Last active September 28, 2022 07:22
shared library command create
g++ -shared -o libmy_math.so my_math.o
@domiyanyue
domiyanyue / run.txt
Last active May 9, 2020 22:47
static library command use 1
g++ main.o -L. -lmy_math -o a.out
@domiyanyue
domiyanyue / run.txt
Last active May 9, 2020 20:30
static library command use 1
g++ main.o libmy_math.a -o a.out
@domiyanyue
domiyanyue / run.txt
Last active May 9, 2020 21:13
static library ar command example
ar cr libmy_math.a my_math.o
@domiyanyue
domiyanyue / run.txt
Created May 8, 2020 03:58
static_library_compile_as_normal
g++ -c main.cpp -o main.o
g++ -c my_math.cpp -o my_math.o
g++ main.o my_math.o -o a.out
./a.out
0.5
@domiyanyue
domiyanyue / main.cpp
Created May 8, 2020 03:54
static_library_main
#include "my_math.h"
#include <iostream>
int main(){
std::cout << reciprocal(2.0) << std::endl;
return 0;
}
@domiyanyue
domiyanyue / 1_my_math.h
Created May 8, 2020 03:50
static_libarary_library_file
#ifndef H_MY_MATH
#define H_MY_MATH
double reciprocal(double d);
#endif // H_MY_MATH
@domiyanyue
domiyanyue / time.h
Last active May 3, 2020 21:38
pragma once example
#pragma once
struct Time {
int hour;
int minute;
};
void printTime(Time t);
@domiyanyue
domiyanyue / _main.cpp
Last active April 28, 2020 03:08
fixed with header guard main
...
#ifndef TIME_H
#define TIME_H
// replaced from first #include "time.h"
struct Time {
int hour;
int minute;
};
...
#endif