How to compile c++ programs in the new c++ driver provided by Datastax in Linux - cql

I am new to Cassandra. I installed c++ driver from Datastax. Can some one please provide me the steps like in which path I have to create the ā€˜.cā€™ file and how I can compile it. I can see some example programs in example folder. Can anyone plz tell me how to compile the example programs.

The cpp-driver uses cmake and depends on libuv. So the first steps would be to ensure you have cmake installed as well as libuv. Depending on your linux distribution it may be as simple as using package manager like apt or yum (i.e. sudo apt-get install cmake libuv-dev)
Building is just a matter of running the following steps in the cpp-driver directory:
cmake .
make
sudo make install
This will install libcassandra.so to somewhere in your lib path. You can then link by providing '-lcassandra' in your parameters to clang or gcc (i.e. clang myfile.c -o myfile -lcassandra)
There is very comprehensive documentation on building from source here.

Related

Paho MQTT throws undefined reference error during compile

I have a problem using Paho MQTT client in C.
I downloaded the pre built binaries for my system (Windows 10 64) from their projects page. I unpacked the zip file to a folder in the documents folder, where I also created a .c file with the example at the bottom of the Paho product page. My editor is atom and my compiler is gcc.
When I tried to compile it in Atom, I got this error:
undefined reference to MQTTClient_create'
So I went searching and found plenty of topics, but I still couldn't figure out, how to resolve this issue. From this stackoverflow topic I gather that it's a linker problem and that I need to link the files during compile, so here's what I tried:
gcc MQTT.c -L "C:\Users\Pete\Documents\MQTT on C\Examples\Paho\lib" -l paho-mqtt3c
Which still gives me the same undefined reference error. When I try to link to the dll of the same name, the compiler does not find the file.
Can anyone point me in the right direction, please?
Any help is appreciated!
I'd be interested to know if you have registered the Paho MQTT dll in Windows?
You should have paho-mqtt3c.dll as part of the download.
I don't know if this will work for you, but I have the same issue (undefined reference to MQTTClient_create)...
Copy the dll file into c:/windows/system32
Run CMD Prompt as Administrator and type:
regsvr32 i/ paho-mqtt3c.dll
Worth a try.
The problem was that I was compiling the program with the 32-bit gcc compiler for the 64-bit library. Installing and using MinGW64 worked.
I had the same issue in OS X. This is how I resolved it
I compiled the paho-mqtt library in Linux/EC2 instance.
Installed all the dependencies:
sudo yum install install build-essential gcc make cmake cmake-gui cmake-curses-gui
sudo yum install cmake
sudo yum install doxygen graphviz
cmake -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_DOCUMENTATION=FALSE -DPAHO_BUILD_STATIC=TRUE -DPAHO_BUILD_SHARED=FALSE -DPAHO_MQTT_C_PATH=../paho.mqtt.c/ -DPAHO_MQTT_C_LIB=../paho.mqtt.c/src/libpaho.mqtt3as-static.a
make
make html
make install
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/ec2-user/paho.mqtt.c/src
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
sudo ldconfig
gcc test1.c -o test1 -lpaho-mqtt3c
Compiled successfully..
./test1
This solution works for OS X as well. Replace step 2 with
brew install cmake doxygen openssl-devel

./configure: No such file or directory cygwin Freeglut

I'm trying to generate the lib files for freeglut library. I've installed cygwin and according to README file that comes with the library,
Building and Installing the Libraries with Cygwin
=================================================
To build "freeglut" under Cygwin, you have two choices:
- You can build a normal Cygwin library, which depends on Cygwin's X11
libraries. To do this, you can just use the normal autotools incantation:
./configure && make install
- Alternatively, you can build a DLL which does not depend on X11 and links
against the opengl32 DLL. To do this, configure need a few more flags:
./configure CPPFLAGS=-mno-cygwin LDFLAGS=-mno-cygwin --without-x && make install
If you don't have MSVC, Open Watcom or Cygwin
=============================================
But If I run ./configure, I got this error
$ ./configure CPPFLAGS=-mno-cygwin LDFLAGS=-mno-cygwin --without-x && make install
-bash: ./configure: No such file or directory
Is there something I need to install in order to solve this issue? The contents of the folder doesn't have configure. These are the files in the folder
If you need freeglut, you need to install the cygwin package libglut-devel
Looking inside setup.ini you will find its description:
libglut-devel
sdesc: "OpenGL Utility Toolkit library"
ldesc: "freeglut
is a completely OpenSourced alternative to the OpenGL Utility Toolkit
(GLUT) library. GLUT was originally written by Mark Kilgard to support
the sample programs in the second edition OpenGL 'RedBook'. Since
then, GLUT has been used in a wide variety of practical applications
because it is simple, widely available and highly portable. GLUT (and
hence freeglut) allows the user to create and manage windows
containing OpenGL contexts on a wide range of platforms and also read
the mouse, keyboard and joystick functions."
category: X11

problems building CodeLite

Having a heck of a time trying to build CodeLite for an ARM-based Ubuntu Linux target. (Build instructions here: http://codelite.org/Developers/Linux). I get an error from CMAKE that says Could not locate GTK2. Looking in the CmakeLists.txt file I can see that this is a result of find_package(GTK2) failing to find GTK2. I think I have installed gtk according to what the CodeLite build instructions say to do using the command sudo apt-get install libgtk2.0-dev.
In terms of cmake, I don't understand what a "package" is. How would I [manually] locate this package on my filesystem and how do I get cmake to find it?
For my aarch64 ubuntu 17.04, the libraries and headers were under /usr/lib/aarch64-linux-gnu, so invoking cmake with them produced the correct build files:
cmake -DCMAKE_INCLUDE_PATH=/usr/lib/aarch64-linux-gnu/ -DCMAKE_LIBRARY_PATH=/usr/lib/aarch64-linux-gnu/ -DCMAKE_BUILD_TYPE=Release .. -DCOPY_WX_LIBS=1

Linux software installation - override version of library in ./configure

I'm trying to install the software TinyOWS on a Linux computer. The source code is written in C programming language. I don't have much experience with installing C or C++ programs from source code on Linux. I read installation instructions, and it says that I must follow 3 steps after I unzip the source code folder:
./configure
make
make install
When I run ./configure, I get the following error:
checking for xml2-config... /usr/bin/xml2-config
checking for libxml2 version... 2.7.6
configure: error: You need at least libxml 2.8.0
This means that the software being installed requires version 2.8.0 of a library called libxml2 but my computer only has the 2.7.6 version. Unfortunately I found out that I cannot easily install the libxml 2.8.0 on my Linux distribution. The reason why the software TinyOWS that I'm trying to install requires libxml2.8.0 of the library is because libxml2.7.6 has a small bug. But most of the functionality of the software is not affected by the bug.
So, here is my question:
What files do I have to edit or what command line options do I need to use If I want the ./configure command to use the library libxml2.7.6 instead of libxml2.8.0?
Get the source, in the file configure.in replace the line:
AC_MSG_ERROR([You need at least libxml 2.8.0])
By
AC_MSG_NOTICE([You need at least libxml 2.8.0])
Then, do:
autoreconf -f -i -s
./configure
make
The configure step will not stop. But i think if the developpers have restricted this version of libxml2 there must be a good reason.

Building mysql++ libraries for powerpc

I have an embedded application written in C++ (running on a PowerPC in linux environment) which accesses an external database. So my application needs mysql++ libraries which needs to be built using a powerpc compiler. Before building the libraries, I wanted to build mysql++ libraries for linux on my Ubuntu VM to check the procedure. I downloaded the latest package from Official Website. Then I followed the steps mentioned.
Ran ./configure from the root directory, I got the below error.
*checking for MySQL library directory... configure: error: Didn't find mysqlclient library in '/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql'*
I tried locate mysqlclient and did not find any references, hence I followed instructions given in other forums and tried to install the libmysqlclient15-dev using the below command.
sudo apt-get install libmysqlclient15-dev
The output is as shown below
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'libmysqlclient-dev' instead of 'libmysqlclient15-dev'
libmysqlclient-dev is already the newest version.
The following packages were automatically installed and are no longer required:
libcommons-collections3-java junit4 libecj-java libdb5.1-java libasm3-java libgcj-bc gcj-4.6-jre-lib libgnomeui-common libcommons-el-java
junit linux-headers-3.2.0-32 linux-headers-3.2.0-29 libcommons-compress-java libregexp-java libdb-java libswt-cairo-gtk-3-jni libjasper-java
libbonoboui2-common libbonoboui2-0 libdb5.1-java-gcj libcommons-httpclient-java libservlet2.4-java liblucene2-java libswt-gtk-3-java
libcommons-cli-java libslf4j-java libgcj12 libxml-commons-external-java libswt-webkit-gtk-3-jni linux-headers-3.2.0-29-generic-pae
libswt-gtk-3-jni ant gcj-4.6-base libcommons-logging-java default-jdk libswt-glx-gtk-3-jni libcommons-codec-java jarwrapper
libequinox-osgi-java libgcj-common libapache-pom-java libgnomeui-0 libjetty-java libjline-java libxerces2-java sat4j
libcommons-beanutils-java libdb-je-java fastjar libcommons-digester-java libcommons-parent-java libhamcrest-java libjtidy-java
libxml-commons-resolver1.1-java libicu4j-java linux-headers-3.2.0-32-generic-pae libicu4j-4.4-java libwebkitgtk-1.0-common
libcommons-lang-java libwebkitgtk-1.0-0 libjavascriptcoregtk-1.0-0 libjsch-java ant-optional libswt-gnome-gtk-3-jni
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
After this I tried to locate libmysqlclient and I still couldn't find the libraries (.so files). I tried ./configure again and it failed in the same location with the same error message. How can I install libmysqlclient ?
Once this is solved I will rebuild the mysql++ library using my toolchain for powerpc. Has anyone tried this ? To build mysql++ library I need mysqlclient, in the earlier example I would install it by executing the command apt-get, but the libraries would be compiled using a gnu compiler ? How to cross compile mysqlclient for powerpc ? I guess I need to do the below
Build mysqlclient for powerpc.
Use those libraries and build mysql++ libraries for powerpc.
Use mysql++ and mysqlclient libraries in my application and compile for powerpc.
I am new to linux and databases.
I finally solved this problem. I did the below.
Downloaded the Connector/C (libmysql) source files from here
Cross compiled it for powerpc, below is the command given to cmake
cmake -DCMAKE_INSTALL_PREFIX="~/mysqlclient_C/lib" -DCMAKE_C_COMPILER="ppc_4xx-gcc" -DCMAKE_C_FLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include/" -DCMAKE_CXX_COMPILER="ppc_4xx-g++" -DCMAKE_CXX_FLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include/" -DCMAKE_EXE_LINKER_FLAGS="-lm"
Then a simple make generated the libmysql libraries.
Downloaded mysql++ source files from here
Cross compiled it for powerpc, below is my configure command
./configure --target=powerpc-linux --host=powerpc-linux --prefix="$HOME/mysql++/lib" --enable-thread-check --with-mysql="$HOME/mysqlclient_C/lib" CC=ppc_4xx-gcc CXX=ppc_4xx-g++ LDFLAGS=-lm CFFLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include" CXXFLAGS="-I/opt/ELDK/4.2/ppc_4xx/usr/include"
The mysql++ libraries is generated now.
I have not tested the built libraries yet.

Resources