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

bazel build somecpp_library fails if it depends on another library #67

Closed
pmbethe09 opened this issue Mar 26, 2015 · 8 comments
Closed
Assignees

Comments

@pmbethe09
Copy link
Member

make the following:
cc_library(name="A", ...)
cc_library(name="B", srcs=["b.cpp"], deps=[":A"], ...)
cc_binary(name="main", ..., deps=[":B"])

bazel build :main works just fine (it correctly puts libA.so and libB.so on the link line)
bazel build :A - same
but bazel build :B will fail with:

From Linking lib/libB.so:
Undefined symbols for architecture x86_64:
"...."
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ERROR: lib/BUILD:3:1: Linking of rule '//lib:lib' failed: gcc failed: error executing command /usr/bin/gcc -shared -o bazel-out/local_darwin-fastbuild/bin/lib/libB.so bazel-out/local_darwin-fastbuild/bin/lib/_objs/lib/lib/b.pic.o -lstdc++ -B/usr/bin -Wl,-S: com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.

It appears that liba.so is missing from the command

@lberki
Copy link
Contributor

lberki commented Mar 27, 2015

This is very surprising. Couldn't reproduce with this BUILD file on Linux, though:

cc_library(
name = "a",
srcs = ["a.cpp"],
)

cc_library(
name = "b",
srcs = ["b.cpp"],
deps = [":a"],
)

cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [":b"],
)

Assigning to Damien since he knows a tad more about Mac than I do.

@damienmg
Copy link
Contributor

Cannot reproduce:

    # Regression test for https://github.com/google/bazel/issues/67
    # C++ library depedending on C++ library fails to compile on Darwin
    function test_cpp_libdeps() {
        mkdir -p pkg
        cat <<'EOF' >pkg/BUILD
    cc_library(
      name = "a",
      srcs = ["a.cc"],
    )

    cc_library(
      name = "b",
      srcs = ["b.cc"],
      deps = [":a"],
    )

    cc_binary(
      name = "main",
      srcs = ["main.cc"],
      deps = [":b"],
    )
    EOF

        cat <<'EOF' >pkg/a.cc
    #include <string>

    std::string get_hello(std::string world) {
      return "Hello, " + world + "!";
    }
    EOF

        cat <<'EOF' >pkg/b.cc
    #include <string>
    #include <iostream>

    std::string get_hello(std::string);

    void print_hello(std::string world) {
      std::cout << get_hello(world) << std::endl;
    }
    EOF

        cat <<'EOF' >pkg/main.cc
    #include <string>
    void print_hello(std::string);

    int main() {
       print_hello(std::string("World"));
    }
    EOF

        bazel build //pkg:a >& $TEST_log \
            || fail "Failed to build //pkg:a"
        bazel build //pkg:b >& $TEST_log \
            || fail "Failed to build //pkg:b"
        bazel run //pkg:main >& $TEST_log \
            || fail "Failed to run //pkg:main"
        expect_log "Hello, World!";
    }

Succeed on my mac I will commit it to share it but the output is clean. I might have forgotten a flag though

EDIT NOTE: I added the two build to the test case to have a failing test case for future reference.

@damienmg
Copy link
Contributor

\o/ I have a failing test

@pmbethe09
Copy link
Member Author

Add an a.h which b.cc includes and calls a function from.
On Mar 27, 2015 6:45 AM, "lberki" [email protected] wrote:

This is very surprising. Couldn't reproduce with this BUILD file on Linux,
though:

cc_library(
name = "a",
srcs = ["a.cpp"],
)

cc_library(
name = "b",
srcs = ["b.cpp"],
deps = [":a"],
)

cc_binary(
name = "main",
srcs = ["main.cpp"],
deps = [":b"],
)

Assigning to Damien since he knows a tad more about Mac than I do.


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

@damienmg
Copy link
Contributor

The problem is that darwin clang expect to have all the dependency provided at compile time. It is not going to be fast to fix.

@damienmg
Copy link
Contributor

I edited the test case in my previous message to have an actually failing one for future reference.

@damienmg damienmg assigned lberki and unassigned damienmg Apr 8, 2015
@kayasoze
Copy link

I've encountered this issue as well.

@aimeeble
Copy link

I've been hitting this too. I've worked around the issue by adding:

linker_flag: "-undefined"
linker_flag: "dynamic_lookup"

into my CROSSTOOL file. Not sure the larger implications of this style lookup though. But, it's enough for me to actually compile, so I'm happy for now.

@damienmg damienmg assigned damienmg and unassigned lberki May 15, 2015
laszlocsomor added a commit to laszlocsomor/bazel that referenced this issue Jul 30, 2018
Running with --nobatch then --batch ensures the
second run kills the first one (because of changed
startup flags) and the second one too (because of
--batch).

The `kill` assertions in lines bazelbuild#66 and bazelbuild#67 now
succeed.

Change-Id: Ibee4997783a820858fc2d2bdda02082a91385d0e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants