ld out of memory when compling cudnn sample

Running on Kubuntu 18.04 x64 with a 1080ti. I’m trying to install the latest version of cudnn (7.4.1). I have cuda 10 installed, no problem.

I’ve installed cudnn on other machines without any issues. I’ve tried both a manual install and a dpkg install. Whenever I try to compile something with cudnn, I get the following error:

/usr/bin/ld: out of memory allocating 281474976710656 bytes after a total of 835584 bytes
collect2: error: ld returned 1 exit status

e.g. from the install sample:

rm -rf *o
rm -rf mnistCUDNN

/usr/bin/ld: out of memory allocating 281474976710656 bytes after a total of 835584 bytes
collect2: error: ld returned 1 exit status
>>> WARNING - FreeImage is not set up correctly. Please ensure FreeImage is set up correctly. <<<
[@] /usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o fp16_dev.o -c fp16_dev.cu
[@] g++ -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
[@] g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
[@] /usr/local/cuda/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o mnistCUDNN fp16_dev.o fp16_emu.o mnistCUDNN.o -I/usr/local/cuda/include -IFreeImage/include -LFreeImage/lib/linux/x86_64 -LFreeImage/lib/linux -lcudart -lcublas -lcudnn -lfreeimage -lstdc++ -lm

Also not sure why it’s moaning about Freeimage, since it’s distributed in the folder and the lib exists (also installed via apt for sanity). The problem is ld. It’s not an out of memory error, ld is trying to allocate 2^48 bytes. I would guess this is a path problem, but the libraries definitely exist in places where nvcc can find them.

Is it a compatibility problem with 18.04? I can compile cuda code without any problems, it’s only when I add cudnn into the mix (e.g. I can build darknet with cuda enabled, but not with cudnn too).