Using ArrayFire libraries - c++

I downloaded the free version of ArrayFire library. I tried to test matrix multiplication with it. However I got a bunch of undefined references such as
matrixdata.cpp:(.text+0x19e5): undefined reference to af::array::array<unsigned char>(int, int, unsigned char const*, af::af_source_t, int)
matrixdata.cpp:(.text+0x1a22): undefined reference to af::array::operator=(af::array const&)'
matrixdata.cpp:(.text+0x1a31): undefined reference to af::array::~array()
Naturally I noticed that I haven't linked arrayfire libraries in my makefile.
However, all my attempts to link the libraries have failed. Can someone please tell what command should I add to link the proper libraries
The files in the lib folder are:
libafcpu.so
libafcuda.so
libafopencl.so
libclBLAS.so
libclBLAS.so.2
libclBLAS.so.2.3.0
libclFFT.so
libclFFT.so.2
libclFFT.so.2.3.0
libStatTimer.so
libStatTimer.so.2
libStatTimer.so.2.3.0

After installation, add the path to the shared libraries of ArrayFire to your LD_LIBRARY_PATH variable. Once you do that, it is merely indicating the correct backend library you need with -l option. Say for cpu, it would be -lafcpu.
What command are you trying ?

Related

How to fix undefined references after libtorch custom build?

I've built libtorch from source (as shared objects) with the purpose of slimming it down, but now when I try to link it into an application, I get this:
error: undefined reference to 'std::invalid_argument::invalid_argument(char const*)'
...
error: undefined reference to 'torch::serialize::OutputArchive::write(std::string const&, at::Tensor const&, bool)'
This doesn't happen when I link with the corresponding pre-built libtorch instead. My application links with -lstdc++ -ltorch -ltorch_cpu -lc10. I've noticed that
Some of these undefined references are from std, others from torch. This surprises me - how is it possible I'm missing stuff from std when I'm linking in stdc++?
The pre-built libtorch includes several .so's I don't have, such as glom. None of these seem necessary to my application though, and I don't need to link them in when using pre-built libtorch.
So what might be the reason I'm getting these undefined references, or how can I go about debugging it?

Unable to link CCfits example program

This is probably related to
c++ reading fits file using ccfits
which was never answered.
Anyway, I hope my question is easier to reproduce. There is an example program for CCfits at:
http://heasarc.gsfc.nasa.gov/fitsio/CCfits/html/cookbook.html
I am attempting to compile this using:
g++ cookbook.cpp -o cookbook -lCCfits -lcfitsio
The link fails for every CCfits function in the file:
/tmp/cc7hVaju.o: In function main':
cookbook.cpp:(.text+0x14): undefined reference towriteImage()'
cookbook.cpp:(.text+0x31): undefined reference to writeAscii()'
cookbook.cpp:(.text+0x4e): undefined reference towriteBinary()'
cookbook.cpp:(.text+0x6b): undefined reference to copyHDU()'
cookbook.cpp:(.text+0x88): undefined reference toreadHeader()'
cookbook.cpp:(.text+0xa5): undefined reference to readImage()'
cookbook.cpp:(.text+0xc2): undefined reference toreadTable()'
cookbook.cpp:(.text+0xdf): undefined reference to readExtendedSyntax()'
cookbook.cpp:(.text+0xfc): undefined reference toselectRows()'
collect2: error: ld returned 1 exit status
I have tried this with the CCfits package that comes with Ubuntu. I have also tried installing the package myself. Same error.
Strangely, I get similar messages if I do not include the libraries on the command line (i.e., "g++ cookbook.cpp -o cookbook"). The one difference is that I also get this error:
/tmp/ccMVMkSB.o: In function CCfits::FITS::setVerboseMode(bool)':
cookbook.cpp:(.text._ZN6CCfits4FITS14setVerboseModeEb[_ZN6CCfits4FITS14setVerboseModeEb]+0xf): undefined reference toCCfits::FITS::s_verboseMode'
This must be a clue, right? Seems to say that the libraries I have named, although they exist, do not contain all the functions I need.
Thanks for any help,
Charles
Not sure if you got a suitable answer to this question but as far as I can tell the main issue is that you are not including the definitions to the function signatures. These are usually defined in the header files of c++ libraries.
For example, if your library is installed in "/usr/local" on a UNIX system then the header files will be installed in the location "/usr/local/include/CCfits". The corresponding lib files will be installed at "/usr/local/lib". The important thing is that the compiler does not know this and you need to inform it of these locations.
g++ cookbook.cpp -o cookbook -I /usr/local/include/CCfits -L /usr/local/lib -lCCfits -lcfitsio
The "-I /usr/local/include/CCfits" flag and the given parameter inform g++ of the location of the header files that it is looking for. The "-L /usr/local/lib" flag and the given parameter inform g++ of the location of the library files. It is important to note that g++ will search in the standard location for libraries on in your environment as well this is just giving it more locations to search. There are in fact rules for what it should do if it finds multiple libraries which are the same in different locations but I don't explicitly remember those.
Also to be safe, ensure that the libraries are loaded into memory by the OS. These are shared libraries not static so they are not stored into the executable file. This won't make a difference when compiling the source but will prevent the successful execution of the executable. To ensure that the OS has loaded the library into memory run the following command:
sudo ldconfig
Yours Aye,
Omar EQ

How to Install/Use libcurl with C++ on Windows/Eclipse CDT

Can someone please explain how to use libcurl with C++ on Windows with Eclipse CDT/Code::Blocks or a similar IDE?
I'm very new to C++ but I know my way around Java very well.
I'm using MinGW but I keep getting this error:
C:\Core\src>g++ -I"C:\curl\include\curl" -L"C:\curl\lib64" -lcurldll core.cpp -o
core.exe
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xc81): undefined
reference to `_imp__curl_easy_init'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xca7): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcc4): undefined
reference to `_imp__curl_easy_setopt'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xcd1): undefined
reference to `_imp__curl_easy_perform'
C:\Users\Bob\AppData\Local\Temp\cc2BV0HI.o:core.cpp:(.text+0xce1): undefined
reference to `_imp__curl_easy_cleanup
What I've Tried:
If I give the wrong library path/name it will tell me that it can not find the library. So clearly it FOUND the libcurldll.a/libcurl.a files but it isn't linking with them properly.
I've tried putting the actual libcurl.dll file from the bin into every source folder possible in my project.
I've tried going to C/C++ General > Paths and Symbols then added "curl" and "curldll" to libraries and "C:\curl\lib64" to the library search path.
I've tried manually adding the -lcurl, -lcurldll, -DCURL_STATICLIB, -L"C:\curl\lib64" options to the MinGW Linker tool.
This has been stumping me for days. Please help.

Linking Intel's MKL (BLAS & LAPACK) to GCC

I am trying to compile a giant software package, and this is the last hurdle I can't seem to figure out.
I'm getting errors like:
RNDiracDeterminantBase.cpp:(.text+0x22bf): undefined reference to `dgetrf_'
RNDiracDeterminantBase.cpp:(.text+0x2524): undefined reference to `dgetri_'
RNDiracDeterminantBase.cpp:(.text+0x3005): undefined reference to `dgetri_'
../../lib/libqmcwfs.a(RNDiracDeterminantBase.cpp.o): In function `qmcplusplus::RNDiracDeterminantBase::ratio(qmcplusplus::ParticleSet&, int, qmcplusplus::ParticleAttrib<qmcplusplus::TinyVector<double, 3u> >&, qmcplusplus::ParticleAttrib<double>&)':
RNDiracDeterminantBase.cpp:(.text+0x4156): undefined reference to `dgemv_'
RNDiracDeterminantBase.cpp:(.text+0x420f): undefined reference to `dger_'
Google reveals that these references are to Intel's MKL library. However, I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in:
/mkl/lib/intel64/
Can post more information if requested.
I don't know what file I need to link. I've tried libmkl_core.a, libmkl_gnu_thread.a, libmkl_blacs_intelmpi_lp64.a, etc. There's tons of files in: /mkl/lib/intel64/
The fact that there are tons of files doesn't mean you have to try each library in turn.
To find out which library defines the symbols you want, run this command:
cd /mkl/lib/intel64
nm -A *.a | egrep '[TWBD] (dger_|dgemv_|dgetrf_|dgetri_)$'
Also be sure to put libraries at the end of your link line, as the order of archive libraries on command line matters.
Based on the incomplete information you provided, it's likely that you need libmkl_intel_lp64.a, libmkl_gnu_thread.a, and libmkl_core.a.
Intel MKL has a built-in tool to help you figure out linking: /mkl/tools/mkl_link_tool. This tool is also available on the web: http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor. Use this tool to get the exact link line for your situation.
You should have asked your question on the official MKL forum (http://software.intel.com/en-us/forums/intel-math-kernel-library). You'd get the answer for this type of questions within hours instead of days.
I had a similar problem when setting up mingw on windows.
The following library linking order worked for me with gcc:
mkl_intel_thread
mkl_rt
mkl_core
mkl_intel_lp64
Hope this helps anyone stuck with this problem.

Adding Boost.Log to boost libraries using CMake

I am trying to add Boost.Log to the Boost libraries using CMake, but I am having trouble when trying to link into my program.
I've added a wrapper around the Boost.Log and generated a shared library called libcls_utils.so. The Boost libraries (along with Boost.Log) appear to be built and generate all the .so files properly in the correct location, and so does libcls_utils.so.
When I try to link my file, I get the following error:
/media/data/workspace/mdxdev/tmp/staging/i686-mv-linux/usr/lib/libcls_utils.so: undefined reference to `boost::log_mt_posix::sinks::basic_text_file_backend::construct(boost::fil‌​esystem2::basic_path, std::allocator >, boost::filesystem2::path_traits> const&, std::_Ios_Openmode, unsigned long long, boost::function0 const&, bool)
As far as I can tell, I'm linking against all the correct libraries. Has anyone tried this before successfully? What am I doing wrong?
I am using CMake 2.8.8, Boost-1.49.0 and Boost.Log from the svn trunk.
You might need to define BOOST_LOG_DYN_LINK:
g++ -DBOOST_LOG_DYN_LINK blog.cpp -lboost_log -lpthread