Building and installing MongoDB C++ driver in OS X - c++

I have downloaded the latest version of MongoDB C++ driver for my os x from http://dl.mongodb.org/dl/cxx-driver. Then I extracted using tar xvf command in os x terminal. After that I run scons to build the driver. It build successfully by giving following messages
-- some messages --
ranlib build/libmongoclient.a
ranlib: file: build/libmongoclient.a(backtrace.o) has no symbols
ranlib: file: build/libmongoclient.a(posix_fadvise.o) has no symbols
ranlib: file: build/libmongoclient.a(ssl_manager.o) has no symbols
Install file: "build/libmongoclient.a" as "libmongoclient.a"
scons: done building targets.
So, then I run the command "scons install" to install the library into my machine.
--some messages --
scons: done reading SConscript files.
scons: Building targets ...
scons: `install' is up to date.
scons: done building targets.
But when I check into the /usr/local directory for the libmongoclient libs, It's not there.
But inside my extracted mongoDB driver folder, there is a file with the name of "libmongoclient.a". But there is no file with the extension of ".dylib". Then How do I use mongoDB Xcode & gcc C++ ?
Somebody help me to link with "libmongoclient" library from Xcode.

It took me a while to get this working.
Hopefully you can get yours working from the following steps:
Create a new C++ project in Xcode
I copied the code from <mongo_driver_install>/src/mongo/client/examples/tutorial.cpp as a test
In Build Settings/Search Paths:
Add the following to your Header Search Paths:
/path/to/mongo-cxx-driver-nightly/src
and your equivalent path for the boost library header files (the folder should contain a boost folder):
/usr/local/Cellar/boost/1.54.0/include
Add the following to your Library Search Paths:
/usr/local/lib (in my case holds all of the boost libraries)
/path/to/mongo-cxx-driver-nightly
Link Binaries
In the Build Phases/Link Binary with Libraries settings:
Add the following binaries:
/path/to/mongo-cxx-driver-nightly/libmongoclient.a
/usr/local/lib/libboost_thread-mt.dylib
/usr/local/lib/libboost_system-mt.dylib
/usr/local/lib/libboost_filesystem-mt.dylib
/usr/local/lib/libboost_program_options-mt.dylib

Related

Build and install libsocketcan for x86_64

I have downloaded the the libsocketcan project and built and installed it successfully (no errors) using:
./autogen.sh
./configure
make
make install
and the configure step outputs:
checking build system type... x86_64-pc-linux-gnu
By my program still complains about the missing libsocketcan file:
qt.canbus.plugins.socketcan: Cannot load library socketcan: (socketcan: cannot open shared object file: No such file or directory)
qt.canbus.plugins.socketcan: Cannot load library libsocketcan, some functionality will not be available.
Cannot load library socketcan: (socketcan: cannot open shared object file: No such file or directory)
I notice that libsocketcan.* can be found in /usr/local/lib, but not in /usr/local/lib64. I think thats the problem. Why are the above steps not building and installing the 64-bit versions of the library? I tried symlinking the .so file into the /usr/local/lib64 but it had no effect. I also tried adding the path to the /usr/local/lib/libsocketcan.so in the ld.config.conf file but also no effect (and I ran ldconfig).
I'm working in Fedora 34 x86_64.

Installing FTP Client (Library) in C++ Ubuntu

I have found this library https://github.com/embeddedmz/ftpclient-cpp on GitHub but how to install it on Linux(Ubuntu) is quite obscure.
You will need CMake to generate a makefile for the static library or
to build the tests/code coverage program. Also make sure you have
libcurl and Google Test installed.
You can follow this script
https://gist.github.com/fideloper/f72997d2e2c9fbe66459 to install
libcurl.
This tutorial will help you installing properly Google Test on Ubuntu:
https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
The CMake script located in the tree will produce Makefiles for the
creation of the static library and for the unit tests program.
To create a debug static library and a test binary, change directory
to the one containing the first CMakeLists.txt and :
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE:STRING=Debug
make
It is not clear to me what "to the one containing the first CMakeLists.txt" refers to. Is it the one in the Gtest? The one in Curl? Or What?
After trying both (the Cmake in Gtest and Curl) I still get the error: "No such file or directory" while trying to #include "FTPClient.h" .
UPDATE:
Listing what I am doing:
I did git clone https://github.com/embeddedmz/ftpclient-cpp.git then made the build folder, navigate into it, I tried cmake .. -DCMAKE_BUILD_TYPE:STRING=Debug (this is the literal command I inserted) and I get
Cmake Error at CmakeLists.txt: 27 (add_subdirectory): add_subdirectory given source "TestFTP" which is not an existing directory
So what is wrong so far?
After you build the library, there will be a libftpclient.a generated in your build tree.
You can install it to your system as follows:
In this case, copy libftpclient.a to /usr/local/lib and the two header files in FTP to /usr/local/include.
You should then be able to include the header files by adding the -I/usr/local/include flag and link by adding -L/usr/local/lib -lftpclient.

How to build libtorch on mac arm?

i downloaded libtorch and make these files on macbook pro ARM:
example-app/
build/
libtorch/
CMakeLists.txt
example-app.cpp
then i used these commands for build torch:
cmake -DCMAKE_PREFIX_PATH=/path-to-example-app/example-app/libtorch
make
and i get this error:
building for macOS-x86_64 but attempting to link with file built for unknown-arm64
can you help me?
I was able to build libtorch library from source on my Mac M1 and run the C++ example-app project that you are looking at
(https://medium.com/#albertsundjaja/installing-pytorch-c-api-d52c722f47ec)
I did it with the following steps:
% git clone -b master --recurse-submodule https://github.com/pytorch/pytorch.git
% mkdir pytorch-build
% cd pytorch-build
% cmake -DBUILD_SHARED_LIBS:BOOL=ON -DCMAKE_BUILD_TYPE:STRING=Release -DPYTHON_EXECUTABLE:PATH=`which python3` -DCMAKE_INSTALL_PREFIX:PATH=../pytorch-install ../pytorch
% cmake --build . --target install
The above process creates a directory called pytorch-install. Copy files from the following directories in pytorch-install to respective directories in /example-app/libtorch/
bin
include
lib
share
Important Note: replace files not directories or some needed files from original libtorch will be lost.
Once I do this, I can run the following command per the tutorial:
% cmake -DCMAKE_PREFIX_PATH=/path-to-example-app/example-app/libtorch ..
make
then running the command
% ./example-app
I get
0.1816 0.6954 0.8272
0.7898 0.0256 0.1385
[ CPUFloatType{2,3} ]
Because libtorch build default only for x86 arch, not for arm arch.
Probably you need to compile it for yourself.
I mean you the libtorch you download is pre-built library, which contains .so files. And this will not work, because pytorch only provide pre-build library for x86 architecture. And you are using an arm architecture cpu.
You need to download the libtorch source code, and build libtorch from scratch.
And after you build the libtorch from scratch, you will get binary file .so which is suitable to link on arm architecture cpu.

How to install LAPACK for MSVS 2010 on windows?

I am using the ITPP library (IT++ library) for one of my projects. For using the eigen_sym() function of this library, it asks for installing the LAPACK. I tried the direct prebuilt libraries for Windows but still get the error. Finally on the following site:
http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries
I found a solution under "Build Instructions to create LAPACK and LAPACKE 3.5.0 dlls for Windows with MinGW" that might work. I did steps 1 to 5 but got stuck 6 onwards.
My destination of the cmake build is E:/LAPACK
I got an error while in the cmd prompt while entering:
cd E:/LAPACK 3.5.0 >Enter
C:/MinGW/bin/mingw32-make.exe >Enter
i'm getting
mingw32-make.exe> No targets specified and no make file found. Stop.
Can someone explain the step 6 onwards in detail and tell me where i'm going wrong?
I finally want to get the .dll and .lib files.
I was able to build LAPACK 3.5 for windows using mingw and pretty much the build guide from the LAPACK page. Using the following steps
Download lapack.tgz from here http://netlib.org/lapack/lapack.tgz
Extract to a folder. I used 7zip file manager to extract the tarball to x:/Other/test
Install mingw32. I used this: http://www.mingw.org/download/installer and I selected and installed mingw32-developer-toolkit + mingw32-base + mingw32-gfortran + mingw32-gcc-g++ + msys-base
Open a command prompt
Append mingw to your path
path=C:/Mingw/bin;%PATH%
change directory to the location you extracted lapack: For me this was X:\Other\Test\lapack-3.5.0 so the command I typed was the following (your path will be different):
C:\Users\jdrescher>x:
X:>cd Other\Test\lapack-3.5.0
X:\Other\Test\lapack-3.5.0>
make a folder for your build. I used build
X:\Other\Test\lapack-3.5.0>mkdir build
then change directory to the build folder
X:\Other\Test\lapack-3.5.0>cd build
X:\Other\Test\lapack-3.5.0\build>
Now configure with CMake
X:\Other\Test\lapack-3.5.0\build>cmake -G "MinGW Makefiles" -D BUILD_SHARED_LIBS=ON -D CMAKE_GNUtoMS=ON ..
Now use gnu make to build LAPACK
X:\Other\Test\lapack-3.5.0\build>c:\MinGW\bin\mingw32-make.exe
Note: This step will take several minutes.
After the above steps completed 100% with no errors, I have the following dlls in the build\bin folder: libblas.dll, liblapack.dll, libtmglib.dll
Also the following libraries, and exp files in the build\lib folder: libblas.exp, libblas.lib, liblapack.exp, liblapack.lib, libtmglib.exp and libtmglib.lib.

Including and using libraries with autotools

I am an autotools newbie; I'm doing an application that needs to parse xml files, using xerces-c 3.1.
My code works fine when I install the xerces-c library with the apt-get utility (then xerces-c libraries and include files are installed in /usr/lib and /usr/include/xercesc, respectively). In my configure.ac file I have the following macro:
AC_CHECK_LIB([xerces-c],[main],[],[AC_MSG_ERROR([*** xerces-c lib not found])])
OK, as I said, this works as expected. However, I want to have the libraries inside the project directory (to be included in the distribution package), and here my problems begin.
I uninstall the xerces-c libraries, and I copy the xerces-c libraries (downloaded from the xerces-c webpage) to my project directory. Then, I add the to my confgure.ac the macro:
LDFLAGS="$LDFLAGS -L/home/xxxx/workspace/P3/src/lib"
Finally, I generate the makefiles and compile, just executing the following commands in the project root directory:
autoconf
automake
./configure
make
The compilation looks good, and the linking looks fine too:
g++ -g -O2 -L/home/xxxx/workspace/P3/src/lib -o app app-P3.o -lxerces-c
But when I execute the application I got an error like:
./src/app: error while loading shared libraries: libxerces-c-3.1.so: cannot open shared object file: No such file or directory
What I'm doing wrong?
Thanks in advance.
Since you are using a shared library libxerces-c-3.1.so needs to be somewhere where it can be found by ld. In the previous case where you installed the xerces-c package, libxerces was installed in /usr/lib or somewhere where it could be found. You can probably get it working for now by:
LD_LIBRARY_PATH=$PATH:/home/xxxx/workspace/P3/src/lib ./src/app
but this is something that you'll have to figure out eventually for your package install.