1、首先编译静态openssl 、alsa-lib和zlib 静态库
编译静态openssl
$./config no-dso no-shared CFLAGS=-static CXXFLAGS=-static LDFLAGS=-static
$make
$sudo make install
编译静态zlib
$./configure --static
$make
$sudo make install
编译静态alsa-lib
$./configure --enable-static=yes --enable-shared=no --with-libdl=no
$ make
$ make install
2、修改assistant-sdk-cpp 下的Makefile 文件
Note:
warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
solution:
compile glibc with config --enable-static-nss
and link program with compiled glibc (-L path/to/build/glic)
https://stackoverflow.com/questions/3430400/linux-static-linking-is-dead
‘--enable-static-nss’
Compile static versions of the NSS (Name Service Switch) libraries. This is not recommended because it defeats the purpose of NSS; a program linked statically with the NSS libraries cannot be dynamically reconfigured to use a different name database.
https://sourceware.org/glibc/wiki/FAQ
Even statically linked programs need some shared libraries which is not acceptable for me. What can I do?
NSS (for details just type `info libc "Name Service Switch"') won't work properly without shared libraries. NSS allows using different services (e.g. NIS, files, db, hesiod) by just changing one configuration file (/etc/nsswitch.conf) without relinking any programs. The only disadvantage is that now static libraries need to access shared libraries. This is handled transparently by the GNU C library.
A solution is to configure glibc with --enable-static-nss. In this case you can create a static binary that will use only the services dns and files (change /etc/nsswitch.conf for this). You need to link explicitly against all these services. For example:
gcc -static test-netdb.c -o test-netdb \
-Wl,--start-group -lc -lnss_files -lnss_dns -lresolv -Wl,--end-group
The problem with this approach is that you've got to link every static program that uses NSS routines with all those libraries.
In fact, one cannot say anymore that a libc compiled with this option is using NSS. There is no switch anymore. Therefore it is highly recommended not to use --enable-static-nss since this makes the behaviour of the programs on the system inconsistent
使用不同版本的gRPC 编译语言助手的步骤:
1、删除安装的gRPC
$sudo rm /usr/local/bin/protoc
$sudo rm -fr /usr/local/lib/
删除protocbuf 相关的文件,这样便于grpc时会自动重新编译protocbuf.
$sudo rm -fr /usr/local/lib/pkgconfig/protobuf*
2、重新编译安装gRPC 和 protoc
3、重新编译googleapis
(参考 assistant-sdk-cpp 下的README.md)
$git clone https://github.com/googleapis/googleapis.git
$git checkout 980cdfa
)
$cd googleapis
$make LANGUAGE=cpp
4、重新编译assistant-sdk-cpp