NVIDIA/cuda-quantum

Link error with nvq++ --enable-mlir -fPIC ...

amccaskey opened this issue · 0 comments

For the simple code

#include "cudaq.h"

__qpu__ void bell() {
    cudaq::qubit q, r;
    h(q);
    x<cudaq::ctrl>(q,r);
}

I get the following error when compiling with -fPIC:

nvq++ --enable-mlir -c bell.cpp -v -fPIC 
/workspaces/cuda-quantum/builds/gcc-12-debug/bin/cudaq-quake -I /workspaces/cuda-quantum/tpls/fmt/include --Xcudaq -fPIC --emit-llvm-file bell.cpp -o bell.qke
/workspaces/cuda-quantum/builds/gcc-12-debug/bin/cudaq-opt --pass-pipeline=builtin.module(func.func(unwind-lowering),canonicalize,lambda-lifting,func.func(memtoreg{quantum=0}),canonicalize,apply-op-specialization,kernel-execution,func.func(indirect-to-direct-calls),inline,func.func(quake-add-metadata),device-code-loader{use-quake=1},expand-measurements,func.func(lower-to-cfg),canonicalize,cse) bell.qke -o bell.qke.TsWyXD
/workspaces/cuda-quantum/builds/gcc-12-debug/bin/cudaq-translate --convert-to=qir bell.qke.TsWyXD -o bell.ll.O2Vj64
/workspaces/cuda-quantum/builds/gcc-12-debug/bin/fixup-linkage bell.qke bell.pre.ll bell.ll
/opt/llvm/bin/llc --relocation-model=pic --filetype=obj -O2 bell.ll.O2Vj64 -o bell.qke.o
/opt/llvm/bin/llc --relocation-model=pic --filetype=obj -O2 bell.ll -o bell.classic.o
/opt/llvm/bin/clang++ -L/workspaces/cuda-quantum/builds/gcc-12-debug/lib -L/workspaces/cuda-quantum/builds/gcc-12-debug/lib/plugins -L/usr/lib/gcc/x86_64-linux-gnu/11 -L/usr/lib/x86_64-linux-gnu -L/usr/lib -L/lib/x86_64-linux-gnu -L/lib -L/usr/local/gdrcopy/lib64 -L/usr/local/cuda/lib64/stubs -r bell.qke.o bell.classic.o -o bell.o
/usr/bin/ld: bell.classic.o: in function `bell()':
bell.cpp:(.text+0x0): multiple definition of `bell()'; bell.qke.o:LLVMDialectModule:(.text+0x60): first defined here
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
failed: "/opt/llvm/bin/clang++ -L/workspaces/cuda-quantum/builds/gcc-12-debug/lib -L/workspaces/cuda-quantum/builds/gcc-12-debug/lib/plugins -L/usr/lib/gcc/x86_64-linux-gnu/11 -L/usr/lib/x86_64-linux-gnu -L/usr/lib -L/lib/x86_64-linux-gnu -L/lib -L/usr/local/gdrcopy/lib64 -L/usr/local/cuda/lib64/stubs -r bell.qke.o bell.classic.o -o bell.o"

Without the -fPIC everything is good to go.