library is linked but reference is undefined

前端 未结 3 1821
太阳男子
太阳男子 2020-12-01 06:05

I\'m trying to compile an openCL program on Ubuntu with an NVIDIA card that worked once before,

#include 
#include 
#include &         


        
相关标签:
3条回答
  • 2020-12-01 06:37

    Alternatively you can add the header and library path to your global variables.

    export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/cuda/include
    export LIBRARY_PATH=$LIBRARY_PATH:/usr/lib/nvidia-current
    

    You can also try to set

    export PATH=$PATH:/usr/local/cuda/bin
    

    It should be possible to run now

    g++ opencl.cpp
    
    0 讨论(0)
  • 2020-12-01 06:48

    From the gcc man page:

       -llibrary
       -l library
           Search the library named library when linking.  (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)
    
           It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified.  Thus, foo.o
           -lz bar.o searches library z after file foo.o but before bar.o.  If bar.o refers to functions in z, those functions may not be loaded.
    
           The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a.  The linker then uses this file as if it had been specified
           precisely by name.
    

    So try to specify the -lOpenCL after the file argument in your compile command.

    You also search for symbols in libOpenCL.so, which is a shared library file. With your command you link your program agains a static library, in the format libOpenCL.a.

    0 讨论(0)
  • 2020-12-01 06:57

    when you are linking, the order of your libraries and source files makes a difference. for example for your case,

    g++ -I/usr/local/cuda/include -L/usr/lib/nvidia-current -lOpenCL opencl.cpp

    functions defined in the OpenCL library might not be loaded, since there nothing before them asking for a look-up. however if you use,

    g++ opencl.cpp -I/usr/local/cuda/include -L/usr/lib/nvidia-current -lOpenCL  
    

    then any requests for functions will be found in the OpenCL library and they will be loaded.

    0 讨论(0)
提交回复
热议问题