19
votes

I am rather new to Linux (using Ubuntu 14.04 LTS 64bit), coming from Windows, and am attempting to port over an existing CUDA project of mine.

When linking via

/usr/local/cuda/bin/nvcc -arch=compute_30 -code=sm_30,compute_30 -o Main.o Display.o FileUtil.o Timer.o NeuralNetwork.o -L/usr/lib -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/cuda/lib64 -lGLEW -lglfw3 -lGL -lGLU -lcuda -lcudart

I encounter the following error:

/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_clipboard.c.o): undefined reference to  symbol 'XConvertSelection'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [CUDANN] Error 1

The answer seems closely related to the solutions in this post (Strange linking error: DSO missing from command line), though given my inexperience with Linux I was unable to adapt them to my own problem.

Any ideas on what the problem could be?

Here is the full output during compilation: https://gist.github.com/wbolden/857eddd11e4dcb915c02

And here is my attempt at a Makefile: https://gist.github.com/wbolden/135033daae04ed0d8cf3

4
The linker is telling you exactly what the problem is, and the answer you linked to tells you exactly what to do to fix it. You are clearly running on a platform that disallows indirect linking. Add the library dependencies for the required additional libraries (hint libX11 is shown right in the linker error message). I am removing the CUDA tag from this question, it has nothing to do with CUDA or CUDA programming. - talonmies
As I said, I am rather new to Linux (I've only been working with it for a few days), so what might be clear to someone with even moderate experience is not all that clear to me. Using ldd I get the following gist.github.com/WilliamHBolden/51a8721b4f8d89df2cef though I don't understand what to do with it. I tried adding -L/usr/x86_64-linux-gnu and -L/lib64 but that did not change the error. - Will Bolden
Maybe you must leave gist or use other system because now gist are not available - Juan Garcia
My username changed, replace WilliamHBolden with wbolden - Will Bolden

4 Answers

36
votes

Hopefully this will be of help to those, like me, who are new to Linux and don't find anything related to Linux to be particularly obvious.

As noted by talonmies, I am not able to link indirectly and as such need to specify any additional libraries required by the libraries I am using. That is to say, if I link library A, which requires libraries B and C, I need to link all three libraries for the program to link correctly.

To find what other libraries were needed I used the pkg-config command, for which I found a guide here. Running pkg-config --print-requires --print-requires-private glfw3 gave the following output, which is the list of packages required by glfw3.

x11
xrandr
xi
xxf86vm
gl

I was then able to find what libraries I needed to include by running pkg-config --libs, followed by the name of the library. For example, pkg-config --libs x11 yielded -lX11.

Note: you can pass multiple items to pkg-config as input, so running

pkg-config --libs $(pkg-config --print-requires --print-requires-private glfw3)

will print out all the additional libraries you need to link (-lX11 -lXrandr -lXi -lXxf86vm -lGL).

My program now links successfully, I hope this helpful to anyone with a similar problem.

7
votes

Your linker need X11 library,You need to specify -lX11 to linker

Try

/usr/local/cuda/bin/nvcc -arch=compute_30 -code=sm_30,compute_30 -o Main.o Display.o FileUtil.o Timer.o NeuralNetwork.o -L/usr/lib -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/cuda/lib64 -lGLEW -lglfw3 -lGL -lGLU -lcuda -lcudart -lX11
1
votes

Try to add -pthread at the end of the library list (command line) in the Makefile.

It worked for me.

0
votes

Use the following commands to fix the issue:

FLAGS=-lX11 ./configure --prefix=/usr --disable-static
make
make install