BUILD:
cc_plugin(
name = 'say',
srcs = ['say.cpp',],
link_all_symbols = True,
dynamic_link = True,
)
say.h
#pragma once
#include
void Say(const std::string& s);
say.cpp:
#include "say.h"
#include
void Say(const std::string& s) {
std::cout<< "hello " << s << std::endl;
}
编译:
blade build --generate-dynamic
BUILD:
需要手动将.h放到include目录中,可以通过shell自动化完成
cc_binary(
name = 'main',
srcs = ['main.cpp',],
deps = [
':say',
],
dynamic_link = True,
)
cc_library(
name = 'say',
incs = ['include'],
prebuilt = True,
)
main.cpp
需要将生成的so放到新创建的lib64_release目录里
#include "include/say.h"
#include
#include
#include
using namespace std;
int main() {
cout << "helll" << endl;
Say("你好");
}
build:
function execshell()
{
echo "[execshell]$@ begin."
eval $@
[[ $? != 0 ]] && {
echo "[execshell]$@ failed."
exit 1
}
echo "[execshell]$@ success."
return 0
}
execshell "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUR_PATH/lib64_release"
blade build --generate-dynamic
将blade-bin中的main拷贝出来,让bin可以链接到so才可以运行: