-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
undefined reference to '__cudaRegisterLinkedBinary'
when adding a CUDA library
#277
Comments
I can successfully compile nvcc -o test_phantom tests/test_phantom.cc \
-Ithird_party/phantom/install/include/phantom \
-Lthird_party/phantom/install/lib \
-lPhantom \
-L/usr/local/cuda/lib64 \
-lcudart -std=c++17 However, in Bazel, even though I set cuda_binary(
name = "test_phantom",
srcs = ["test_phantom.cc"],
copts = [
"-std=c++17",
],
linkopts = [
"-L/usr/local/cuda/lib64",
"-lcudart",
],
deps = [
"//third_party/phantom/install:phantom",
"@local_cuda//:cuda_runtime",
],
) |
First you don't use these type of linkopts in your cuda_binary
They are implicit, otherwise, there will be a bug. Second, it seems you are relying on the relocateable device code, try set |
@cloudhan ,thank you for your reply and help! Following your guidance, I tried the configuration below, but I still received a similar error: cuda_objects(
name = "test_object",
srcs = ["test_phantom.cc"],
copts = [
"-std=c++17",
],
deps = [
"//third_party/phantom/install:phantom",
"@local_cuda//:cuda_runtime",
],
)
cuda_library(
name = "test_lib",
rdc = True,
deps = [
":test_object"
],
)
cuda_binary(
name = "test_phantom",
deps = [
":test_lib",
],
) Additionally, I'm not sure if this is related to relocatable device code, because I found that the following command also compiles successfully (without nvcc -o test_phantom tests/test_phantom.cc -Ithird_party/phantom/install/include/phantom -Lthird_party/phantom/install/lib -lPhantom -std=c++17 |
It seem you are working (relying) on some OSS project, it will be more approachable if you provide me a minimal reproduce repo. This might be a rdc or whole archive linking or maybe combined in your phantom lib. I consider it being related to rdc, pure judged from the |
Hi, @cloudhan . Although I don't know the cause of this error, it has been resolved. Previously, I compiled the CUDA library into a static library using CMake and linked it to my project, which caused the aforementioned error. Following your guidance, I tried to create a minimal reproducible example. During this process, I built the corresponding Once again, I'm really grateful for your help and guidance. This project is really great! |
Hello,
I am attempting to add a CUDA library to my project, but I encountered many errors like
undefined reference to '__cudaRegisterLinkedBinary'
during compilation,The library itself seems to be functioning correctly, and I suspect the problem might be related to how I’ve integrated the library into my Bazel build setup. Below are the details of my setup.
test_phantom.cc:
BUILD file for test_phantom:
BUILD file for CUDA library:
When I run the following command:
I receive the following errors:
I looked into the relevant information about this error, and it seems to be caused by 'relocatable device code linking.' However, most of the available information is about CMake compilation, and there is a lack of solutions for resolving this error in Bazel. I tried adding the following to
test_phantom
...Let me know if you need any further adjustments!
I also tried adding the following
linkopts
to thetest_phantom
rule:But this did not resolve the issue, and the same error persists.
I’m not sure if this is an issue with how I am integrating the CUDA library, or if there's something else I am missing in my Bazel setup. Could you help me identify the root cause of this error? Any guidance or suggestions would be greatly appreciated.
Thank you very much for your help!
The text was updated successfully, but these errors were encountered: