Skip to content

Linker error compiling with clang on linux #3878

@adam-azarchs

Description

@adam-azarchs

When compiling tests with bazel with clang on linux, I get a linker error undefined reference to nextafter.

Does the bug persist in the most recent commit?

Yes.

What operating system and version are you using?

Linux. The specifics don't matter because we're using a custom sysroot, described below.

What compiler and version are you using?

clag version 13.0.0 with --sysroot pointing to a sysroot built using crosstool-ng based on centos7.

What build system are you using?

bazel version 5.1.1.

Additional context

This is basically the same bug as #3601, but the fix for that one made the incorrect assumption that this was only a problem on BSD. The correct solution is to change

googletest/BUILD.bazel

Lines 123 to 125 in 0e40217

":freebsd": ["-lm", "-pthread"],
":openbsd": ["-lm", "-pthread"],
"//conditions:default": ["-pthread"],

to be simply

    "//conditions:default": ["-lm", "-pthread"], 

It won't do any harm when using compilers like gcc which add -lm implicitly, but it will prevent breakage for compilers which do not do this.

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