Libraries

C++相关的技巧

C++动态链接库的编译

源代码

extern "C"
{
    int add(int a, int b);
}

class Test
{
public:
    int add(int a, int b)
    {
        return a + b;
    }
};

int add(int a, int b)
{
    Test t;
    return t.add(a, b);
}

编译命令

g++ test.cpp -o test.so -fPIC --shared

查看符号表

nm test.so | grep test.so