How to link to a different libc file?

I found out how to do it: rpath specifies where the provided libraries are located. This folder should contain: libc.so.6, libdl.so.2, libgcc_s.so.1 and maybe more. Check with strace to find out which libraries your binary file uses. ld.so is the provided linker gcc -Xlinker -rpath=/default/path/to/libraries -Xlinker -I/default/path/to/libraries/ld.so program.c

Should variable definition be in header files?

One thing that I’ve used in the past (when global variables were in vogue): var.h file: … #ifdef DEFINE_GLOBALS #define EXTERN #else #define EXTERN extern #endif EXTERN int global1; EXTERN int global2; … Then in one .c file (usually the one containing main()): #define DEFINE_GLOBALS #include “var.h” The rest of the source files just include … Read more

library is linked but reference is undefined

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 … Read more