我正在尝试从Google差异隐私框架中创建一个.so
文件,以在另一个(非巴兹)项目中导入它。
C代码只是标题文件。对于构建过程,他们使用Bazel,所以我试图坚持下去。 我在Stackoverflow上查看了各种解决方案。他们中的大多数建议这应该有效:
cc_binary(
name= "lib.so",
linkshared=1,
srcs=["header.h","src.c"],
deps=["//framwork:dependency1"],
)
但是,在我的情况下,这似乎不起作用。我认为这是由于我只有.h文件来源。 这就是我得到的:
cc_binary(
name= "lib.so",
linkshared=1,
srcs=[
"header1.h",
"header2.h",
...],
deps=["//framwork:dependency1", ...],
)
使用此.SO文件进行编译时,但是内部没有符号或代码。因此,我使用的cc_binary
规则似乎存在问题。 在cc_binary
中使用linkstatic
没有任何区别。
Bazel执行的GCC命令上述规则看起来像这样:
gcc -shared -o lib.so -Wl,-S -fuse,ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -Wl,--start-lib logging.pic.o -Wl,--end-lib -Wl,--start-lib hash.pic.o -Wl,--end-lib ... -pthread -pthread -pthread -lpthread -lm -lpthread -lm -lstdc++ -lm
而不是点,还有更多.pic.o
文件,这些文件插入了- start-lib 和
- end-lib
。不知何故,这个命令似乎是错误的,但我不知道该如何解决。
查看Bazel项目GitHub页面上的讨论,似乎创建.so
文件似乎是Bazel的弱点之一。
有人知道这里可能出了什么问题吗?使用CC_SHARED_LIBRARY
解决方案吗?如果是,我将如何使用它? 提前致谢!
I am trying create an .so
file from the Google Differential Privacy framework to import it in another (non-Bazel) project.
The C code is only header files. For the build process they use bazel, so I am trying to stick with that.
I looked at various solutions on StackOverflow. Most of them suggested that this should work:
cc_binary(
name= "lib.so",
linkshared=1,
srcs=["header.h","src.c"],
deps=["//framwork:dependency1"],
)
However, this does not seem to work in my case. I assume this is due to the fact that I only have .h files for sources.
This is what I got:
cc_binary(
name= "lib.so",
linkshared=1,
srcs=[
"header1.h",
"header2.h",
...],
deps=["//framwork:dependency1", ...],
)
When compiling with this an .so file is created but there are no symbols or code inside. Therefore, there seems to be a problem with the cc_binary
rule I used.
Using linkstatic
in cc_binary
did not make any difference.
The gcc command executed by Bazel for the rule above looks something like this:
gcc -shared -o lib.so -Wl,-S -fuse,ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -Wl,--start-lib logging.pic.o -Wl,--end-lib -Wl,--start-lib hash.pic.o -Wl,--end-lib ... -pthread -pthread -pthread -lpthread -lm -lpthread -lm -lstdc++ -lm
Instead of the dots there are a lot more .pic.o
files which are inserted with --start-lib
and --end-lib
. Somehow this command seems wrong but I don't know how to fix it.
Looking at the discussions on the Github page of the Bazel project, it seems that creating .so
files seems to be one of the weak points of Bazel.
Does anyone have an idea what might go wrong here? Is using cc_shared_library
a solution to this? If yes, how would I use it?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我正在尝试做的事情并没有真正的意义。
I found this post which talks about header-only Cmake中的库。
由于没有C文件,因此无法创建对象文件。因此,可以创建任何.SO文件。
如该帖子中所述,我将尝试创建一个.c文件,该文件只包含所有.h文件以创建.so文件。
It seems like what I was trying to do did not really make sense.
I found this post which talks about header-only libraries in CMake.
Since there are no c files, no object files can be created. Therefore, no .so file can be created.
As described in that other post I will try to create a .c file which simply includes all .h files to create a .so file.