【发布时间】:2019-02-13 16:46:15
【问题描述】:
我正在尝试在我的 c 程序中使用一些 cos/sin 函数和 dlopen/sym 函数,并将其放在我的“BUILD”文件中:
cc_binary(
name = "hello-dl",
srcs = ["hello-dl.cc"],
deps = ["dl"],
)
我的源文件是:
#include<stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
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;
}
我的图书馆是:
# cat hello-greet.cc
#include<stdio.h>
void f(){
printf("f function\n");
}
当我运行 bazel 时,它给出了一些错误:
bazel build hello-dl
INFO: Invocation ID: 89be69f9-5b70-4318-8b6a-43ad6feb341c
ERROR: /root/mynet/mytest/build/useBazel/cpp-project/BUILD:9:12: in deps attribute of cc_binary rule //:hello-dl: target '//:dl' does not exist
ERROR: Analysis of target '//:hello-dl' failed; build aborted: Analysis of target '//:hello-dl' failed; build aborted
INFO: Elapsed time: 0.115s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
那么我该如何解决这个问题?非常感谢。
【问题讨论】:
标签: c++ dependencies bazel