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

Buck fails to link, linkage order seems to be wrong in linker.argsfile #2741

Open
stephenlindauer opened this issue May 31, 2023 · 1 comment

Comments

@stephenlindauer
Copy link

stephenlindauer commented May 31, 2023

I'm trying to build Nvidia's jetson multimedia api samples with Buck so I can integrate into a project but wanted to test things out first. I built the BUCK file (below) from their Rules.mk file and I believe everything is the same.

cxx_binary(
    name = "nvenc",
    srcs=glob([
        "samples/01_video_encode/*.cpp",
        "samples/common/classes/*.cpp"
    ]),
    deps = [],
    include_directories = [
        "include",
        "include/libjpeg-8b",
        "samples/common/algorithm/cuda",
        "samples/common/algorithm/trt",
        "/usr/local/cuda/include",
        "/usr/include/aarch64-linux-gnu",
        "/usr/include/libdrm",
        "/usr/include/opencv4"
    ],
    linker_flags=[
        "-pthread",
        "-lv4l2",
        "-lEGL",
        "-lGLESv2",
        "-lX11",
        "-ldrm",
        "-lnvbuf_utils",
        "-lnvjpeg",
        "-lnvosd",
        "-lcudart",
        "-lcuda",
        "-L/usr/local/cuda/lib64",
        "-L/usr/lib/aarch64-linux-gnu",
        "-L/usr/lib/aarch64-linux-gnu/tegra"
        ],
    visibility = [ "PUBLIC" ]
)

Linking fails though with hundreds of undefined reference errors to the libraries I'm trying to link to. Looking at the linker.argsfile, it shows:

-o
buck-out/gen/nvenc
-pthread
-lv4l2
-lEGL
-lGLESv2
-lX11
-ldrm
-lnvbuf_utils
-lnvjpeg
-lnvosd
-lcudart
-lcuda
-L/usr/local/cuda/lib64
-L/usr/lib/aarch64-linux-gnu
-L/usr/lib/aarch64-linux-gnu/tegra
buck-out/gen/nvenc#compile-NvApplicationProfiler.cpp.o23383382,default/samples/common/classes/NvApplicationProfiler.cpp.o
buck-out/gen/nvenc#compile-NvBuffer.cpp.o87c60479,default/samples/common/classes/NvBuffer.cpp.o
buck-out/gen/nvenc#compile-NvDrmRenderer.cpp.o896cf551,default/samples/common/classes/NvDrmRenderer.cpp.o
buck-out/gen/nvenc#compile-NvEglRenderer.cpp.o6cab9d20,default/samples/common/classes/NvEglRenderer.cpp.o
buck-out/gen/nvenc#compile-NvElement.cpp.o54736403,default/samples/common/classes/NvElement.cpp.o
buck-out/gen/nvenc#compile-NvElementProfiler.cpp.o6ba19734,default/samples/common/classes/NvElementProfiler.cpp.o
buck-out/gen/nvenc#compile-NvJpegDecoder.cpp.o89873dc1,default/samples/common/classes/NvJpegDecoder.cpp.o
buck-out/gen/nvenc#compile-NvJpegEncoder.cpp.ode8d1c57,default/samples/common/classes/NvJpegEncoder.cpp.o
buck-out/gen/nvenc#compile-NvLogging.cpp.oec03456e,default/samples/common/classes/NvLogging.cpp.o
buck-out/gen/nvenc#compile-NvUtils.cpp.o65f73625,default/samples/common/classes/NvUtils.cpp.o
buck-out/gen/nvenc#compile-NvV4l2Element.cpp.o466b928e,default/samples/common/classes/NvV4l2Element.cpp.o
buck-out/gen/nvenc#compile-NvV4l2ElementPlane.cpp.o3b27c505,default/samples/common/classes/NvV4l2ElementPlane.cpp.o
buck-out/gen/nvenc#compile-NvVideoConverter.cpp.o6b052a55,default/samples/common/classes/NvVideoConverter.cpp.o
buck-out/gen/nvenc#compile-NvVideoDecoder.cpp.o3630241f,default/samples/common/classes/NvVideoDecoder.cpp.o
buck-out/gen/nvenc#compile-NvVideoEncoder.cpp.o78373a29,default/samples/common/classes/NvVideoEncoder.cpp.o
buck-out/gen/nvenc#compile-video_encode_csvparser.cpp.o2b367cbf,default/samples/01_video_encode/video_encode_csvparser.cpp.o
buck-out/gen/nvenc#compile-video_encode_main.cpp.o9e95d1a8,default/samples/01_video_encode/video_encode_main.cpp.o

and I notice all the libraries are before all the .o files. If I move the libraries to the end and manually run g++ with these args, it builds successfully. Is there a param I'm setting wrong or not setting in my buck file that can fix this?

@stephenlindauer
Copy link
Author

Forgot to include system info.

$ buck --version
buck version 9c7c421e49f4d92d67321f18c6d1cd90974c77c4
$ uname -a
Linux jetsonnano 4.9.253-tegra #1 SMP PREEMPT Sat Feb 19 08:59:22 PST 2022 aarch64 aarch64 aarch64 GNU/Linux

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant