Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compile problem #331

Closed
ouclbc opened this issue Jul 28, 2023 · 14 comments
Closed

compile problem #331

ouclbc opened this issue Jul 28, 2023 · 14 comments

Comments

@ouclbc
Copy link

ouclbc commented Jul 28, 2023

we can use g++ -o server server.cc example.pb.cc -std=c++11 -lsrpc -lworkflow -lsnappy -lz -lprotobuf to compile example.
but if I do not install srpc and workflow and protobuf, How can I compile? I know we can use -L ,but where is the generated so?
can you move all the needed so to _lib and include to _include?

@ouclbc
Copy link
Author

ouclbc commented Jul 28, 2023

errors as like this:
undefined reference to `google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'

@holmes1412
Copy link
Contributor

All .so and headers of wokflow and srpc are already located in their _lib and _include.

This error is because libprotobuf.so cannot be found. You need to specify the default location which installed protobuf in your environment, usually in /usr/local.

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

thank you for your infomation,but what I want to know is when cross compile,where can I find the target temp so? /usr/local that is local compile and install can find.

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

交叉环境在使用bin时,如下库也是需要:libz.so libworkflow.so libprotobuf.so,但是编译产物里面没有,这个请问我需要一个个模块单独编译么?

@holmes1412
Copy link
Contributor

holmes1412 commented Jul 31, 2023

其实一共需要:workflow lz4 snappy zlib protobuf openssl

先前我们recursive拉的代码,包含了前三个,可以在普通环境下make完看看:

  • 其中workflow在srpc项目根目录/workflow/_libs和_include下,应该已经编译好了,指定一下路径链接一下就行
  • snappy和lz4在third_party/各自的目录下,是用来压缩的,我看你上面没有列,可能你已经搞定了
  • 然后是zlib和openssl,一般系统都会自带,所以我猜你如何交叉编译openssl的你也需要对zlib这样交叉编译一下(也是用来压缩的库)
  • 最后是protobuf,不知道你的嵌入式环境下一般如何安装protobuf呢?如何系统没有自带,你需要单独编译。

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

多谢哈,我理解为应该是依赖模块都需要交叉编译,除非系统自带某些库。我试一下各个模块交叉编译吧。

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

我发现我直接从官方拉snappy代码,可以编译过,用srpc目录下面的snnappy编译,有如下错误
In file included from /home/barton/work/srpc/third_party/snappy/snappy-test.cc:31:0:
/home/barton/work/srpc/third_party/snappy/snappy-test.h: In member function ‘void snappy::CycleTimer::Start()’:
/home/barton/work/srpc/third_party/snappy/snappy-test.h:133:7: error: ‘::gettimeofday’ has not been declared
::gettimeofday(&start_, nullptr);
^~~~~~~~~~~~
/home/barton/work/srpc/third_party/snappy/snappy-test.h: In member function ‘void snappy::CycleTimer::Stop()’:
/home/barton/work/srpc/third_party/snappy/snappy-test.h:149:7: error: ‘::gettimeofday’ has not been declared
::gettimeofday(&stop, nullptr);
^~~~~~~~~~~~
CMakeFiles/snappy_test_support.dir/build.make:75: recipe for target 'CMakeFiles/snappy_test_support.dir/snappy-test.cc.o' failed
make[2]: *** [CMakeFiles/snappy_test_support.dir/snappy-test.cc.o] Error 1
CMakeFiles/Makefile2:204: recipe for target 'CMakeFiles/snappy_test_support.dir/all' failed
make[1]: *** [CMakeFiles/snappy_test_support.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2

@holmes1412
Copy link
Contributor

holmes1412 commented Jul 31, 2023

gettimeofday这个函数并不跨平台,我看了下你给的文件名:third_party/snappy/snappy-test.h,它这里是这样的:

inline void Start() {
#ifdef WIN32
    QueryPerformanceCounter(&start_);
#else
    ::gettimeofday(&start_, nullptr);
#endif
}

这里对于非windows的话都用gettimeofday的话,在嵌入式环境下会有问题。

你拉的snappy应该是适合你的环境的包,应该以你从官方拉下来的snappy为准就好~

@holmes1412
Copy link
Contributor

压缩这些库感觉某些场景也不太需要,以前是觉得库比较小、系统自带,不费事。

我今天晚点加一个编译选项,让srpc编译可选不需要压缩库,也许交叉编译这种场景可以方便一点。

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

太酷啦,点赞点赞。

@ouclbc
Copy link
Author

ouclbc commented Jul 31, 2023

还有个问题请教哈,我编译出来的./srpcserver,执行的时候为啥去找libsrpc.so.0,我理解为最终生成一个so即可,其他的so都是软连接的,所以我把libsrpc.so.0.10.0重命名为libsrpc.so应该可以,但是发现执行的时候还是去找libsrpc.so.0,不太明白。
error while loading shared libraries: libsrpc.so.0: cannot open shared object file: No such file or directory

@holmes1412
Copy link
Contributor

是因为链接的时候,如果是采用动态链接,-lsrpc,系统会使用版本号标识不同的.so。可以通过ldd命令查看到,实际上可执行文件是依赖的libsrpc.so.0,而不是libsrpc.so,所以你重命名了也不行。比如(不知道你的系统上有ldd脚本不):

[root@XXXX]# ldd srpc_pb_server
        libsrpc.so.0 => /root/srpc/srpc_1412/_lib/libsrpc.so.0 (0x00007f1a4896e000)
        libworkflow.so.0 => /root/srpc/srpc_1412/workflow/_lib/libworkflow.so.0 (0x00007f1a488bb000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f1a48892000)
        libssl.so.1.1 => /lib64/libssl.so.1.1 (0x00007f1a485fe000)
        libcrypto.so.1.1 => /lib64/libcrypto.so.1.1 (0x00007f1a48110000)
        libprotobuf.so.23 => /usr/local/lib/libprotobuf.so.23 (0x00007f1a47e72000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f1a47e58000)
        ...

解决办法有两个:

  1. 链接时不要用-lsrpc,而是指定名字libsrpc.so,记得加上-L指定路径
  2. 使用静态连接,比如在cmake文件中加set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ${CMAKE_FIND_LIBRARY_SUFFIXES})试试看

@ouclbc
Copy link
Author

ouclbc commented Aug 1, 2023

先不用去压缩了,目前我在嵌入式Linux跑起来了,后续Android系统的有可能还需要请教您哈。

@ouclbc ouclbc closed this as completed Aug 1, 2023
@holmes1412
Copy link
Contributor

太厉害啦~如果有空的时候可以帮写一下步骤分享给后面需要的小伙伴就太好了。

好的,压缩有空了慢慢改~有其他问题随时交流

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants