linux 动态库编译

dynamic_library.hpp

#pragma once

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



dynamic_library.cpp

#include "dynamic_library.hpp"

extern "C" int addition_function(int a, int b)
{
	return a + b;
}

g++ -c dynamic_library.cpp #生成.o文件

g++ -shared -fPIC -o libdy.so dynamic_library.cpp

ldconfig `pwd`  #加入动态库目录地址

g++ -o app -L. -ldy mainapp.cpp


mainapp.cpp

#include "dynamic_library.hpp"

void TestLIB()
{
	std::cout << addition_function(10,22) << std::endl;
}






你可能感兴趣的:(linux 动态库编译)