简体   繁体   中英

Is it scons don't support LDFLAGS?

I am new in scons. I am trying to build a program with gRPC by scons. I use grpc_lib = commands.getoutput('pkg-config --libs protobuf grpc++') to get LDFLAGS. The grpc_lib is a string

-L/home/zty/.local/lib -lprotobuf -lpthread -lgrpc++ -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations -lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_exponential_biased -labsl_hash -labsl_bad_variant_access -labsl_city -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations -lgpr -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations -lssl -lcrypto

So my SConstruct is below, but it did not link with LDFLAGS.

import os
import commands
from SCons.Script import *
grpc_lib = commands.getoutput('pkg-config --libs protobuf grpc++')
grpc_cflags = commands.getoutput('pkg-config --cflags protobuf grpc')

mainEnv = Environment(ENV = os.environ)

mainEnv['CXX'] = 'g++'
mainEnv.Append(CXXFLAGS = '-std=c++11')
mainEnv.Append(CPPPATH = '../protos')
mainEnv.Append(CPPFLAGS = grpc_cflags)
mainEnv.Append(LDFLAGS = grpc_lib)

sources = Split("""
                ../protos/CSmalloc.grpc.pb.cc
                ../protos/CSmalloc.pb.cc
                server.cc
                """)
mainEnv.Program('server',sources)

output

g++ -o /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.grpc.pb.o -c -std=c++11 -lpthread -I/home/zty/.local/include -I/home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.grpc.pb.cc
g++ -o /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.pb.o -c -std=c++11 -lpthread -I/home/zty/.local/include -I/home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.pb.cc
g++ -o server.o -c -std=c++11 -lpthread -I/home/zty/.local/include -I/home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos server.cc
g++ -o server /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.grpc.pb.o /home/zty/lsnvmm-pmalloc/examples/grpc-CS/protos/CSmalloc.pb.o server.o

By the way, is there a more easy way to build C++ program with gRPC?

It's easier if you use mainEnv.ParseConfig , it can split out the results on running pkg-config directly into the correct construction variables.

As to gRPC... there's at least some experimental work on the internet about using protobufs smoothly with scons. This is one of them, not sure if it's the "best" version or not: https://github.com/SCons/scons/wiki/ProtocBuilder . You probably need more than that... you could join the scons Discord channel to chat further. Edited: hadn't realized the repository that page points to is among the set that were turned off when Bitbucket dropped non-git repositories, but it is archived, not lost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM