У меня есть получил очень простой проект:
Код: Выделить всё
ls
BUILD WORKSPACE hello-dl.cc hello-greet.cc hello-greet.h
cat hello-greet.cc
#include
void f(){
printf("f function\n");
}
cat hello-dl.cc
#include
#include
#include
int main(){
void * handle = dlopen("hello-greet", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
void (*f)() = (void (*)()) dlsym(handle, "f");
char* error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
f();
dlclose(handle);
exit(EXIT_SUCCESS);
return 0;
}
Код: Выделить всё
cc_binary(
name = "hello-dl",
srcs = ["hello-dl.cc"],
linkopts = ['-ldl', '-lm']
)
cc_library(
name = "hello-greet",
srcs = ["hello-greet.cc"],
hdrs = ["hello-greet.h"],
)
Код: Выделить всё
bazel build //:hello-greet
bazel build //:hello-world
Код: Выделить всё
bazel run hello-dl
....
hello-greet: cannot open shared object file: No such file or directory
Подробнее здесь: https://stackoverflow.com/questions/546 ... ut-library