Linking error: DSO missing from command line

前端 未结 4 1509
孤城傲影
孤城傲影 2020-11-30 04:31

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

4条回答
  •  青春惊慌失措
    2020-11-30 04:55

    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.

提交回复
热议问题