Skip to content

cgo: unsure how to link against static library #2681

@irfansharif

Description

@irfansharif

What version of rules_go are you using?

v0.23.8

What version of gazelle are you using?

v0.22.2

What version of Bazel are you using?

3.4.1

Does this issue reproduce with the latest releases of all the above?

Yes.

What operating system and processor architecture are you using?

darwin

Any other potentially useful information about your toolchain?

Nope

What did you do?

I'm trying to link against a C++ library, and I'm unsure how to construct the right clinkopt flags to specify where to find the .a file. I've included the minimal repro here: https://github.com/irfansharif/test-repo

What I'm specifically interested in is the following snippet:

go_library(
    name = "libmain",
    srcs = ["main.go"],
    cdeps = ["//:libroach"],
    cgo = True,
    # TODO(irfansharif): How do we avoid referring to bazel-out/darwin-fastbuild
    clinkopts = [
        "-Lbazel-out/darwin-fastbuild/bin/libroach/lib",
        "-lroach",
    ],
    cppopts = [
        "-Ibazel-out/darwin-fastbuild/bin/libroach/include",
    ],
    importpath = "github.com/irfansharif/test-repo",
    visibility = ["//visibility:private"],
)

Where //:libroach generates the following static library:

    static_libraries = ["libroach.a"],

How am I to get the go library to look towards the right directory where the library is placed? I see it being placed under bazel-out/darwin-fastbuild/bin/libroach/lib, but I assume that's unsafe to hardcode in.

What did you expect to see?

See above.

What did you see instead?

See above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions