I'm trying to compile a program that makes use of OpenCL and CUDA and GPUs. I've attempted to install Nvidia drivers, CUDA, cuDNN, GCC and OpenCL on my Ubuntu 16.10 GTX 1070 machine and, for the most part, things seem to be working. However, I'm still unsure of how to set up OpenCL such that I can compile the program.
At a glance, I'm trying to compile oclvanitygen
, which is an OpenCL program for generating Bitcoin wallets. I run into difficulties when I try to compile it.
>git clone https://github.com/samr7/vanitygen.git
>cd vanitygen
>gcc -o oclvanitygen oclvanitygen.c -lOpenCL
/tmp/ccPaWgka.o: In function `main':
oclvanitygen.c:(.text+0x50c): undefined reference to `vg_exec_context_new_key'
oclvanitygen.c:(.text+0x529): undefined reference to `EC_KEY_get0_group'
oclvanitygen.c:(.text+0x53e): undefined reference to `EC_POINT_hex2point'
oclvanitygen.c:(.text+0x554): undefined reference to `EC_KEY_free'
oclvanitygen.c:(.text+0x815): undefined reference to `RAND_load_file'
oclvanitygen.c:(.text+0x894): undefined reference to `vg_regex_context_new'
oclvanitygen.c:(.text+0x8b8): undefined reference to `vg_prefix_context_new'
oclvanitygen.c:(.text+0x935): undefined reference to `vg_output_match_console'
oclvanitygen.c:(.text+0x947): undefined reference to `vg_output_timing_console'
oclvanitygen.c:(.text+0x9d4): undefined reference to `vg_context_add_patterns'
oclvanitygen.c:(.text+0xa28): undefined reference to `vg_read_file'
oclvanitygen.c:(.text+0xa9c): undefined reference to `vg_prefix_context_set_case_insensitive'
oclvanitygen.c:(.text+0xabb): undefined reference to `vg_context_add_patterns'
oclvanitygen.c:(.text+0xb37): undefined reference to `vg_read_password'
oclvanitygen.c:(.text+0xb86): undefined reference to `vg_check_password_complexity'
oclvanitygen.c:(.text+0xc33): undefined reference to `vg_ocl_context_new_from_devstr'
oclvanitygen.c:(.text+0xcdc): undefined reference to `vg_ocl_context_new'
oclvanitygen.c:(.text+0xd06): undefined reference to `vg_ocl_enumerate_devices'
oclvanitygen.c:(.text+0xd1c): undefined reference to `vg_context_start_threads'
oclvanitygen.c:(.text+0xd41): undefined reference to `vg_context_wait_for_completion'
oclvanitygen.c:(.text+0xd50): undefined reference to `vg_ocl_context_free'
collect2: error: ld returned 1 exit status
What is likely going wrong and how can I fix it?
The specific details of how I set up the system are listed below. I'm guessing that there are some steps I've done incorrectly with regards to letting the compiler have access to what it needs of OpenCL.
I installed Nvidia drivers.
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install \
nvidia-367 \
nvidia-prime \
nvidia-modprobe \
nvidia-opencl-dev
I installed CUDA.
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
This installed CUDA at directory /usr/local/cuda-8.0
. I included directory /usr/local/cuda-8.0/bin
in the PATH environment variable.
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
I installed cuDNN.
tar -xvf cudnn-8.0-linux-x64-v5.1.tgz
The cuDNN archive contains the following:
cuda/include/cudnn.h
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.5
cuda/lib64/libcudnn.so.5.1.10
cuda/lib64/libcudnn_static.a
I copied some of these files to other directories because the internet told me to.
sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include/
sudo cp cuda/lib64/* /usr/local/cuda-8.0/lib64/
I installed and changed to GCC 4.9 for CUDA.
sudo apt-get install gcc-4.9 g++-4.9
ln -fs /usr/bin/gcc-4.9 /usr/bin/gcc
ln -fs /usr/bin/g++-4.9 /usr/bin/g++
OpenCL is included with CUDA. I created a symbolic link to the Nvidia OpenCL headers at directory /usr/include
.
sudo ln -s /usr/include/nvidia-375/CL /usr/include
I linked to the compiled OpenCL library file too:
sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/local/lib/libOpenCL.so
Your problem doesn't seem to be with OpenCL or CUDA, but is instead in the way you're building this particular project.
To build
oclvanitygen
, try instead runningmake oclvanitygen
, or to build it manually:The undefined references listed in your build error, such as
vg_exec_context_new_key
, are from files in the vanitygen project itself, not OpenCL, so adding these files to the build fixes it.