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

Header only libraries do not build on Mac OS X #61

Closed
trevorgray opened this issue Mar 25, 2015 · 13 comments
Closed

Header only libraries do not build on Mac OS X #61

trevorgray opened this issue Mar 25, 2015 · 13 comments
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug

Comments

@trevorgray
Copy link

I'm running Mac OS X 10.10.3. It looks like libtool complains when trying to build header only libraries. Adding an empty cc file to the build rule fixes this, however a warning will be output and it does not feel very clean to have empty cc files littered all over the place.

Sample build rule and output below:

cc_library(
    name = "header-only",
    hdrs = ["hello-lib.h"],
)

$ output/bazel build examples/cpp:header-only
INFO: Found 1 target...
INFO: From Linking examples/cpp/libheader-only.a:
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: no files specified
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
ERROR: /Users/trevorgray/src/github.com/google/bazel/examples/cpp/BUILD:9:1: Linking of rule '//examples/cpp:header-only' failed: libtool failed: error executing command /usr/bin/libtool -static -s -o bazel-out/local_darwin-fastbuild/bin/examples/cpp/libheader-only.a: com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
Target //examples/cpp:header-only failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.232s, Critical Path: 1.10s
@damienmg
Copy link
Contributor

Do you have a empty.c in tools/cpp ?

@trevorgray
Copy link
Author

Yes. This was run from head with only running compile.sh and modifying examples/cpp/BUILD.

$ ls tools/cpp
BUILD       CROSSTOOL   empty.cc

@ulfjack
Copy link
Contributor

ulfjack commented Mar 25, 2015

The rules aren't quite compatible with the Mac tools - that's why we added
the empty.cc in a few places. I have an idea of how to change the rules to
make this go away, but the downside is that it would be technically
incompatible with our internal rules. Alternatively, we could add wrappers
around the Mac tools to make them handle that corner case in a way that's
compatible with the rules.

On Wed, Mar 25, 2015 at 8:20 PM Trevor Gray notifications@github.com
wrote:

Yes. This was run from head with only modifying examples/cpp/BUILD.

$ ls tools/cpp
BUILD CROSSTOOL empty.cc


Reply to this email directly or view it on GitHub
#61 (comment).

@ulfjack
Copy link
Contributor

ulfjack commented Mar 25, 2015

To clarify - the Mac tools don't allow static libraries (and maybe this
also applies to dynamic libraries) which are empty - i.e. which don't
contain any object files, while the Linux tools typically allow this. The
rules, however, have implicit .a and .so outputs which the rules
'guarantee' to always be created, even for empty libraries (the rules can't
determine during the loading phase if there are going to be .cc source
files or not).

On Wed, Mar 25, 2015 at 8:30 PM Ulf Adams ulf@adams.info wrote:

The rules aren't quite compatible with the Mac tools - that's why we added
the empty.cc in a few places. I have an idea of how to change the rules to
make this go away, but the downside is that it would be technically
incompatible with our internal rules. Alternatively, we could add wrappers
around the Mac tools to make them handle that corner case in a way that's
compatible with the rules.

On Wed, Mar 25, 2015 at 8:20 PM Trevor Gray notifications@github.com
wrote:

Yes. This was run from head with only modifying examples/cpp/BUILD.

$ ls tools/cpp
BUILD CROSSTOOL empty.cc


Reply to this email directly or view it on GitHub
#61 (comment).

@damienmg
Copy link
Contributor

I just introduced a wrapper around gcc for another bug (the library path one we discussed on monday), let just do another wrapper around otool for that.

@damienmg
Copy link
Contributor

sorry I means around libtool

@damienmg
Copy link
Contributor

Ulf, I let you handle this one when you are back.

@damienmg damienmg added type: bug P2 We'll consider working on this in future. (Assignee optional) labels Mar 26, 2015
@applmak
Copy link

applmak commented Apr 30, 2015

Is

# libtool_wrapper.sh
set -eu

LIBTOOL="/usr/bin/libtool"
GCC="/usr/bin/gcc"

TOOLS_DIR="$PWD/tools/cpp"

# Ensure that we have an 'empty' .o
if [ ! -e $TOOLS_DIR/empty.o ]; then
  ${GCC} -o $TOOLS_DIR/empty.o -c $TOOLS_DIR/empty.cc
fi

# Call normal libtool with the addition empty .o
${LIBTOOL} "$@" $TOOLS_DIR/empty.o

the worse thing ever to fix this or only the second-worst thing?

@Sinn
Copy link

Sinn commented May 31, 2015

Installed bazel on May 24, cloned from github.

Mac OS X Yosemite, this issue is still present, even though there is an empty.cc on the bazel-project/tools/cpp/ dir. Any idea why?

@kayasoze
Copy link

kayasoze commented Jul 3, 2015

I've encountered the same issue while trying to build Boost on OS X with Xcode 6.4. In that case, adding an empty.cc (with linkstatic = 1 to silence warnings) does not help.

@ulfjack
Copy link
Contributor

ulfjack commented Jul 23, 2015

I'm back now, and this seems like it's critical to fix. I've made some progress on a fix, which is going to be to remove the static / dynamic libraries if there aren't any object files. There's a chance that this breaks users who rely on the implicit output files <name>.a or <name>.so being available, but I don't expect that to be widely used.

For those using the workaround, the empty.cc file needs to be actually referenced in cc_library.srcs (and you'll still get warnings from the linker).

@kayasoze
Copy link

I will often wrap a genrule() built library (built, say, with autoconf) with a cc_library(); among other benefits, this allows me to specify the correct include paths for the library's headers and have them handled transitive-magically. If implicit output files are removed, will this trick still work?

@ulfjack
Copy link
Contributor

ulfjack commented Jul 24, 2015

Yes, that's not a problem. I only know a single use case for the .a or .so implicit outputs, and there's a workaround for that. I also had a quick look through our internal code base, and there are few, if any, places that rely on the 'old' behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) type: bug
Projects
None yet
Development

No branches or pull requests

6 participants