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

Unable to build Envoy with Bazel #2639

Closed
anirudhmurali opened this Issue Feb 18, 2018 · 16 comments

Comments

Projects
None yet
5 participants
@anirudhmurali
Copy link
Member

anirudhmurali commented Feb 18, 2018

Title: Unable to build Envoy with Bazel

Description:
I was getting started with Envoy, and followed the Quick start build for developers.
Installed bazel, golang, buildifier, other required dependencies with Homebrew, fetched the source and built all the external dependencies successfully.

Upon running bazel build //source/exe:envoy-static from Envoy directory, the build doesn't complete successfully, I get:
gcc: error: unrecognized command line option '-fobjc-link-runtime'.
Below is the screenshot of the verbose version:

image

I guess the issue is with gcc and not with Envoy, is there any known fix for this?

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 19, 2018

Updated gcc to 7.3.0 and ran again. Still the same.
gcc: error: unrecognized command line option '-fobjc-link-runtime'; did you mean '-fgnu-runtime'?

@htuch

This comment has been minimized.

Copy link
Member

htuch commented Feb 19, 2018

@zuercher this looks like an OS X issue, any idea?

@zuercher

This comment has been minimized.

Copy link
Member

zuercher commented Feb 20, 2018

I've never tried to build with homebrew-installed gcc, but it looks like bazel is assuming clang and passing clang-specific flags to gcc.

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 20, 2018

It first caused in homebrew-installed gcc 4.9, and then I downloaded the gcc 7.3.0 source, ran configure, make and installed it. The error still persisted. I'll see if it is possible to use clang by default instead of gcc.

@jmillikin-stripe

This comment has been minimized.

Copy link
Contributor

jmillikin-stripe commented Feb 21, 2018

I remember seeing a similar error when upgrading the local Clang toolchain. IIRC the C compiler configuration won't automatically get regenerated if $PATH changes.

Try running bazel clean --expunge ; bazel shutdown, make sure which gcc is the path you expect, and then try building again.

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 21, 2018

image
@jmillikin-stripe Tried it, and ran the build. ^ is what I get. Upon googling c++: error: unrecognized command line option ‘-stdlib=libc++’, came to know that this is clang specific flag again.

Uninstalled the homebrew installed one, and ran it again. Still the same.
The docs say: Envoy compiles and passes tests with the version of clang installed by XCode 8.3.3: Apple LLVM version 8.1.0 (clang-802.0.42).
Now I'm with Xcode 9.2: Apple LLVM version 9.0.0 (clang-900.0.39.2).

image

@jmillikin-stripe

This comment has been minimized.

Copy link
Contributor

jmillikin-stripe commented Feb 21, 2018

Hmm, the BoringSSL build's cmakefile is invoking /usr/local/bin/c++. I've never seen that on a Mac before -- is it from Homebrew? I'm also confused about where -stdlib=libc++ could be coming from, it's not set by Bazel or Envoy and grep didn't have any hits in the BoringSSL code.

I feel like there must be a disconnect between the CC and CXX environment variables, vs your path. I'll try installing gcc 7.3 locally and attempt to reproduce the issue.

@jmillikin-stripe

This comment has been minimized.

Copy link
Contributor

jmillikin-stripe commented Feb 21, 2018

Found the issue. BoringSSL's cmake config hardcodes -stdlib=libc++ when building on Apple platforms. This will be fixed for Envoy when we stop using cmake to build BoringSSL (#2652).

Note that there are other problems that will prevent you from building Envoy on MacOS with a self-installed compiler. Libevent depends on some MacOS system headers, which use macros not supported by stock GCC. I didn't try using Homebrew-managed Clang, but expect similar issues will be hit there.

My recommendation is to stick with the compiler installed by XCode. It may be possible to make libevent build on a MacOS platform with non-standard compilers, but you're going to spend a lot of time digging around in low-level compiler flags to make it happen.

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 21, 2018

Great. I'm okay with using the default compiler which comes with XCode. I've run brew uninstall gcc, deleted the gcc at usr/local/bin/gcc which was installed manually.
Now running gcc --version shows me Apple LLVM version 9.0.0 (clang-900.0.39.2).
I hope this is the default compiler that comes by XCode? I still get the error though. Isn't my uninstallation complete?

@jmillikin-stripe

This comment has been minimized.

Copy link
Contributor

jmillikin-stripe commented Feb 21, 2018

You may need to bazel clean --expunge if you've changed your C/C++ toolchain to something else. You should also verify that g++ --version matches, since BoringSSL and Envoy use g++. And finally, since the log above shows /usr/local/bin/c++ being invoked, consider moving or removing whatever that is.

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 21, 2018

Removed, cleaned, and tried. Now this,
ld: symbol(s) not found for architecture x86_64. Am I missing any particular XCode dependency?
image

@jmillikin-stripe

This comment has been minimized.

Copy link
Contributor

jmillikin-stripe commented Feb 21, 2018

Maybe you've got ld from homebrew and it's not compatible with XCode's clang?

At this point, I recommend trying to clean anything Homebrew-related out of your path. There's no way you can get a working build when half of your toolchain is Apple's heavily-modified Clang, and half is stock GNU.

You might also try following https://docs.bazel.build/versions/master/tutorial/cpp.html to see if you can get a working C++ "hello world" compiled, then proceed from there to Envoy.

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Feb 22, 2018

I followed the bazel hello world tutorial, all 3 exercises run smoothly.
I uninstalled entire Homebrew related packages, and installed just these coreutils, wget, cmake, libtool, automake alone, and ran it, still the same ld error.

@zuercher

This comment has been minimized.

Copy link
Member

zuercher commented Mar 12, 2018

Were you ever able to get this working?

@anirudhmurali

This comment has been minimized.

Copy link
Member

anirudhmurali commented Mar 12, 2018

Sadly no, the same error still persists. Using Ubuntu in VirtualBox to play with Envoy as of now.

@mattklein123

This comment has been minimized.

Copy link
Member

mattklein123 commented Mar 13, 2018

Closing for now. Please hop into Slack #osx-dev room for futher help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment