Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Undefined reference when using pthread #1443

@njlr

Description

@njlr

Compiling a small pthread example results in an undefined reference. It seems that Buck is not handling the linker_flags correctly.

Repo for this issue: https://github.com/njlr/buck-pthread-example

Here is the BUCK file:

cxx_binary(
  name = 'main',
  srcs = [
    'main.cpp',
  ],
  linker_flags = [
    '-lpthread',
  ],
)

Here is the error:

$ buck build :main 
buck-out/gen/main#compile-main.cpp.oa5b6a1ba,default/main.cpp.o: In function `main':
main.cpp:(.text+0x98): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

BUILD FAILED: //:main#binary failed with exit code 1:
c++ link
stderr: buck-out/gen/main#compile-main.cpp.oa5b6a1ba,default/main.cpp.o: In function `main':
main.cpp:(.text+0x98): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

[-] PROCESSING BUCK FILES...FINISHED 0.1s [100%] 🐌  New Buck instance
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.4s [100%] (2/3 JOBS, 1 UPDATED, 1 [33.3%] CACHE MISS)

Compiling manually works:

c++ main.cpp -o main -lpthread

My setup:

$ buck --version
buck version v2017.05.31.01
$ c++ --version
c++ (Ubuntu 6.3.0-12ubuntu2) 6.3.0 20170406
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Priority 3

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions