Skip to content

Instantly share code, notes, and snippets.

@cho0h5
Created December 3, 2021 06:56
Show Gist options
  • Save cho0h5/547246363f737dfdaf0e91ec5318adbb to your computer and use it in GitHub Desktop.
Save cho0h5/547246363f737dfdaf0e91ec5318adbb to your computer and use it in GitHub Desktop.
C 동적 라이브러리
#include "control_light.h"
#include <stdio.h>
int turn_on(int id) {
printf("turn on %d\n", id);
return 0;
}
int turn_off(int id) {
printf("turn off %d\n", id);
return 0;
}
//
// gcc -fPIC -c control_light.c
// gcc -shared -Wl,-soname,libcontrollight.so.0 -o libcontrollight.so.0.0.0 control_light.o
// sudo cp libcontrollight.so.0.0.0 /usr/local/lib/
// sudo ln -s /usr/local/lib/libcontrollight.so.0.0.0 /usr/local/lib/libcontrollight.so.0
// sudo ln -s /usr/local/lib/libcontrollight.so.0.0.0 /usr/local/lib/libcontrollight.so
int turn_on(int id);
int turn_off(int id);
#include "control_light.h"
int main() {
turn_on(13);
turn_on(7);
turn_off(13);
turn_on(7);
return 0;
}
// export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
// gcc main.c -L/usr/local/lib -lcontrollight
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment