共有ライブラリに、main()
ハンドラ()ルーチンのみを提供する実行可能ファイルの作成ルーチンを含めるにはどうすればよいですか?main()で共有ライブラリをハンドラ関数のみを提供する実行可能ファイルにリンクする
[email protected]:/media/Workspace/eclipse/libMain$ cat Makefile
main.so: main.cpp
gcc -shared -o main.so -fPIC main.cpp
libMain.so: main.so
gcc -shared -o libMain.so main.so
test1: libMain.so test1.o
g++ -o test1 test1.o -L. -lMain
test2: libMain.so test2.o
g++ -o test2 test2.o -L. -lMain
all: test1 test2
clean:
rm -f test1 test2 libMain.so *.o *.so
[email protected]:/media/Workspace/eclipse/libMain$ cat main.cpp
void DoSomething(void);
int main(int, char **)
{
DoSomething();
return 0;
}
[email protected]:/media/Workspace/eclipse/libMain$ cat test1.cpp
#include <iostream>
void DoSomething(void)
{
std::cout << "hello from test1" << std::endl;
}
[email protected]:/media/Workspace/eclipse/libMain$ cat test2.cpp
#include <iostream>
void DoSomething(void)
{
std::cout << "hello from test2" << std::endl;
}
これは動作します:
> G ++ -o test1のtest1.o main.so
をメイン()main.so である。しかし、それはlibMain.soではもう利用できませんので(?!)
2番目の共有オブジェクトファイルを完全に削除するには、 'gcc -shared -o libMain.so -fPIC main.cpp'を直接使うことができます – oldrinb