기본 콘텐츠로 건너뛰기

UNIX 공유객체(shared object) 만들기

#include <cstdio>
using namespace std;

extern "C"
{
extern void hello(void);
}

void
hello(void)
{
    printf("void hello(void);\n");
}


g++ -c -fPIC hello.cpp
g++ -shared -lc -o hello.so hello.o

#include <dlfcn.h>
void (*func)(void);

int
main(int,char**)
{
    void* handle(dlopen("./hello.so", RTLD_LAZY));
    func = (void (*)(void))dlsym(handle,"hello");
    func();
    return 0;
}


g++ -o dltest dltest.cpp -ldl

댓글

이 블로그의 인기 게시물

Winget 해시 무시하기

가끔씩 Winget 에서 패키지를 다운로드 했을 때, "설치 관리자 해시가 일치하지 않습니다." 오류가 뜰 때가 있다. 보안 이슈가 있지만, 그냥 무시하고 싶을 때, 아래 순서로 무시해준다. 관리자 권한 winget settings --enable InstallerHashOverride 설치 winget install --ignore-security-hash --id NirSoft.NirCmd