Can't build gRPC with Clang and libc++ on Ubuntu

562 views
Skip to first unread message

al...@resonai.com

unread,
Jul 10, 2017, 2:09:45 PM7/10/17
to grpc.io

Hi,

I'm trying to build gRPC v1.4.1 as following. I have all the required third party libraries built (with Clang and libc++) and installed (besides boringssl which is cloned inside third_party and built recursively).

I'm running make as following:

make HOST_CC=clang HOST_CXX="clang++ -stdlib=libc++ -std=c++11" CC=clang CXX="clang++ -stdlib=libc++ -std=c++11"


and I get an error during linkage of the protoc gRPC plugin:

[HOSTLD]  Linking /grpc-1.4.1/bins/opt/grpc_cpp_plugin

/usr/bin/ld: /grpc-1.4.1/objs/opt/src/compiler/cpp_plugin.o: undefined reference to symbol '_ZNSt3__18ios_base4initEPv'

//usr/lib/x86_64-linux-gnu/libc++.so.1: error adding symbols: DSO missing from command line

collect2: error: ld returned 1 exit status

make: *** [/grpc-1.4.1/bins/opt/grpc_cpp_plugin] Error 1


My constraint is that I really need to build with libc++. The whole thing does work if I build with libstdc++ (given protobuf is built with libstdc++ as well).

I really need your help here, thank you!

Alex

Nicolas Noble

unread,
Jul 11, 2017, 3:19:17 AM7/11/17
to al...@resonai.com, grpc.io
This seems a very straightforward problem: you're specifying -stdlib=libc++ at compilation time, using clang, but you're not overriding the linker nor its options. Moreover, you're using HOST_* variables, which are normally used for cross-compilation. I doubt this is what you want given the context you're saying.

Here's what you should be doing:

export CXX=clang++
export CXXFLAGS=-stdlib=libc++
export LDXX="clang++ -stdlib=libc++" # yep, I just realized that's a bug we have here to not properly support LDXXFLAGS, so you're going to have to use that ugly form instead.

Also, if you really want the pure C part to be compiled using clang, you'd need to add
export CC=clang

but that's got quite nothing to do with using libc++, so it's not a good reason to try and hurt yourself there.

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/d37d91eb-d75e-4d4b-b6b3-b55424705e30%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

al...@resonai.com

unread,
Jul 11, 2017, 4:00:20 AM7/11/17
to grpc.io, al...@resonai.com
Hi Nicolas,
Thank you for the reply, it works (though I also had to add -std=c++11 to CXXFLAGS).
I indeed previously tried to pass -stdlib=libc++ to the linker, but used LDFLAGS by mistake. Passing LDXX as you proposed solved the problem.

Thanks!
Alex
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

Nicolas Noble

unread,
Jul 11, 2017, 11:29:40 AM7/11/17
to al...@resonai.com, grpc.io
Yes, LDXX isn't very standard, but since we are mixing C and C++ binary builds, we need to distinguish between two different linker options. 

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
Reply all
Reply to author
Forward
0 new messages