CPP MQTT Broker code not working - c++

I need to use mqtt broker in a project of mine. But i felt there is a huge lack of documentation. Some of the available example codes i found didn't really work for me. Followed this example, but got compilation error
[subho#localhost] taboo $ g++ mqtt.cpp -o a
/tmp/ccg9xcFV.o: In function `myMosq::myMosq(char const*, char const*, char const*, int)':
mqtt.cpp:(.text+0x31): undefined reference to `mosqpp::mosquittopp::mosquittopp(char const*, bool)'
mqtt.cpp:(.text+0x41): undefined reference to `mosqpp::lib_init()'
mqtt.cpp:(.text+0x9c): undefined reference to `mosqpp::mosquittopp::connect_async(char const*, int, int)'
mqtt.cpp:(.text+0xa8): undefined reference to `mosqpp::mosquittopp::loop_start()'
mqtt.cpp:(.text+0xb9): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
/tmp/ccg9xcFV.o: In function `myMosq::~myMosq()':
mqtt.cpp:(.text+0xf5): undefined reference to `mosqpp::mosquittopp::loop_stop(bool)'
mqtt.cpp:(.text+0xfa): undefined reference to `mosqpp::lib_cleanup()'
mqtt.cpp:(.text+0x106): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
mqtt.cpp:(.text+0x12c): undefined reference to `mosqpp::mosquittopp::~mosquittopp()'
/tmp/ccg9xcFV.o: In function `myMosq::send_message(char const*)':
mqtt.cpp:(.text+0x1b0): undefined reference to `mosqpp::mosquittopp::publish(int*, char const*, int, void const*, int, bool)'
/tmp/ccg9xcFV.o:(.rodata._ZTI6myMosq[_ZTI6myMosq]+0x10): undefined reference to `typeinfo for mosqpp::mosquittopp'
collect2: error: ld returned 1 exit status
Also tried to look into the sample codes given in the mqtt archive but make command failed to compile them. So tried to compile the sample files separately which succeeded but while running it gives buffer overflow and mosquito terminal output is
[subho#localhost] Web_App $ (master) mosquitto
1426996368: mosquitto version 1.3.5 (build date 2014-10-16 10:32:53+0000) starting
1426996368: Using default config.
1426996368: Opening ipv4 listen socket on port 1883.
1426996368: Opening ipv6 listen socket on port 1883.
1426996369: New connection from 127.0.0.1 on port 1883.
1426996369: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426996369: Socket error on client tempconv, disconnecting.
1426997037: New connection from 127.0.0.1 on port 1883.
1426997037: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426997037: Socket error on client tempconv, disconnecting.
1426997314: New connection from 127.0.0.1 on port 1883.
1426997314: New client connected from 127.0.0.1 as tempconv (c1, k60).
1426997314: Socket error on client tempconv, disconnecting.
It would be great if somebody has worked with mqtt before and can share a basic code. Thanks.
I have pushed all the files i tried in github, you can have a look here.

I have the same problem from time to time. Maybe the late answer helps another one, too. Ubuntu has a rather old version of mosquitto. In the meantime it became an eclipse project and some things changed.
This problem occurs, if the mosquitto package of a linux distribution is installed, where the library files go into /usr/lib. For having the header files the source code has to be downloaded and if make install is called, the new library with changed function names or namespace go into /usr/local/lib.
Hence the wrong library is linked.

Related

How to ignore undefined references to libpangocairo library

I have set up a video streaming system with OpenCv and Cairo. Unfortunately, now when I attempt to build, I get all sorts of undefined references to libpangocairo-1.0.so.0. I'd like a solution where I can just ignore these undefined references, or explicitly and exclusively point to the correct dependency.
Side note: I am using CMake.
It seems that my system library files are accidentally being queried instead of the user installed dependencies for OpenCv.
Things I have tried:
• Reinstalled libpangocairo
• Changed the LD_LIBRARY_PATH to explicitly point at our cairo library dependency within the repo
• Updated Glib to 2.27 from 2.0 (source said that Cario/OpenCv depends on the a later version of GLibc - I think he actually said 2.39, which doesn't exist :white_frowning_face:)
• Updated GTK to 3.0 which also contains glib and would install its most recent version
• Copied libpangocairo from /usr/lib to our repositories dependencies (build points correctly to the newly located lib but still same error)
• Completely wiped my environment and set up environment from scratch
Error Message:
//usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0: undefined reference to `cairo_ft_scaled_font_unlock_face'
//usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0: undefined reference to `cairo_ft_font_options_substitute'
//usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0: undefined reference to `cairo_ft_font_face_create_for_pattern'
//usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0: undefined reference to `cairo_ft_scaled_font_lock_face'
collect2: error: ld returned 1 exit status

Arduino undefined reference to `operator

I am working on one project where I am using arduino. I am running Fedora 24 and Arduino IDE 1.6.4. I have wanted to continue in my work yesterday but I could not. New compilation error appeared. Last time everything was working OK. A have also tried some other older working sketches, they display the same error now.
Arduino: 1.6.4 (Linux), Board: "Arduino Nano, ATmega328"
Build options changed, rebuilding all
arduino.cpp.o: In function `setup':
/usr/share/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial.h:111: undefined reference to `operator delete(void*, unsigned int)'
/usr/share/arduino/hardware/arduino/avr/cores/arduino/HardwareSerial.h:111: undefined reference to `operator delete(void*, unsigned int)'
collect2: error: ld returned 1 exit status
Error compiling.
I remember that I was using "dnf update" before and it updated also kernel. I have already tried to reinstall arduino IDE with removing the .arduino15 directory and reinstall all of my libraries. Nothing helps. How can I fix ths compiling error?
I have already solved my problem. I have tried different things but this worked:
uninstall Arduino IDE thru terminal
delete .arduino15 folder
search for any directory called arduino and remove it with sudo rm -r
install the lastest Arduino IDE version directly from https://www.arduino.cc/en/Main/Software

How to solve "undefined reference" for NDK build in Android Studio?

I am getting an "undefined reference" error building my Android app. I am using JNI and the NDK.
What is inexplicable to me is that it seems to be doing an NDK build during my build of the Android app itself. Yet I've already used the command line to build my Android.mk and Application.mk files to produce the desired library. All the the Android app is supposed to do is link to the library and make calls into it. But even if I'm wrong about this, I don't understand why it is complaining about errors in AILSuperFFT.o. This object file is already a part of the library I successfully built. The build process of my Android app should not know anything about AILSuperFFT.cpp or its internal calls to the Superpowered library.
Here's the Console output in Android Studio.
. . .
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/hello-jni//Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.o: In function `CAILSuperFFT::LinearFFT_Quick(DSPSplitComplex*, int, int, int, FFTDirection, bool)':
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.cpp:139: undefined reference to `SuperpoweredFFTComplex(float*, float*, int, bool)'
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.cpp:139: undefined reference to `SuperpoweredFFTComplex(float*, float*, int, bool)'
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/hello-jni//Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.o: In function `CAILSuperFFT::FFT2D(DSPSplitComplex*, int, int, FFTDirection)':
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.cpp:52: undefined reference to `__android_log_print'
collect2: error: ld returned 1 exit status
make: *** [/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/libhello-jni.so] Error 1
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/user1/Documents/NDKDev/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2
BUILD FAILED
and here is very similar output in the Messages window:
:app:incrementalDebugJavaCompilationSafeguard
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/hello-jni//Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.o: In function `CAILSuperFFT::LinearFFT_Quick(DSPSplitComplex*, int, int, int, FFTDirection, bool)':
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/objs/hello-jni//Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.o: In function `CAILSuperFFT::FFT2D(DSPSplitComplex*, int, int, FFTDirection)':
/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/src/main/jni/sources/AILSuperFFT.cpp
Error:(139) undefined reference to `SuperpoweredFFTComplex(float*, float*, int, bool)'
Error:(139) undefined reference to `SuperpoweredFFTComplex(float*, float*, int, bool)'
Error:(52) undefined reference to `__android_log_print'
Error:error: ld returned 1 exit status
make: *** [/Users/user1/Documents/AndroidStudioProjects/hello-jnicpp/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/libhello-jni.so] Error 1
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Users/user1/Documents/NDKDev/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 5.858 secs
Information:5 errors
Upon request below is the source code function call that is being complained about. Note that not only does this code build and link fine using ndk-build in Mac's Terminal, but the resulting library is then used without problem in a different app. I am not able to tell (yet) what is the difference between these two apps, but be aware of the dependencies here: Android app uses our proprietary library, which builds and links in the Superpowered lib. The app only knows about the interface exposed by library A, and all of this works fine in one app. (I'm constructing a test app to demonstrate a certain issue, which can't be done with the main app). Log2() returns an int.
DSPSplitComplex data;
data.imagp=(float *) malloc(sizeof(float)*BUF_SIZE*BUF_SIZE);
data.realp=(float *) malloc(sizeof(float)*BUF_SIZE*BUF_SIZE);
. . . (some code)
DSPSplitComplex *pBuffer = &data;
SuperpoweredFFTComplex(&pBuffer->realp[0]), &(pBuffer->imagp[0]), Log2(length), (direction==kFFTDirection_Forward) ? true : false);
An ndk-build will be attempted if you have JNI files and haven't explicitly turned off the auto-build by adding this to your build.gradle:
android {
sourceSets.main {
jni.srcDirs = []
}
}
If the ndk-build you did prior to building the app worked correctly, the reason is likely that the automated ndk-build called by Gradle ignores your Android.mk file.

gcc/g++ library issues when moving development from Solaris 8 to Solaris 10 (gcc 3.2.1)

first of all a little background about myself: I am not a C/C++ developer, though I learned quite a lot about C and system programming years ago. My primary occupation is Unix admin (with a slant towards Solaris) and I'm trying to help some in-house developers to migrate their development environments from Solaris 8 to Solaris 10.
They used to develop their applications on Solaris 8 up until now. But recently the last Solaris 8 Development machine has been turned off but of course no one bothered to really test if all the applications would compile as well in Solaris 10 as they did in Solaris 8.
Now we have a very specific application that must be compiled with gcc 3.2.1 - I have managed to get the developers to be able to compile, however, the compiled binary won't run in the Production environment - it does in the development environment, though.
The reason for the failure of the compiled binary in the production system is that some libraries are missing:
./myapp
ld.so.1: myapp: fatal: libstdc++.so.5: open failed: No such file or directory
Killed
Now the strange thing is, that this library (and libgcc_s.so.1, too) were not linked against, when the binary was built in Solaris 8 - here are the two outputs of ldd for comparison, first the new one built on Solaris 10 (note the two lines reading "file not found"):
ldd myapp
librt.so.1 => /lib/64/librt.so.1
libpthread.so.1 => /lib/64/libpthread.so.1
libstdc++.so.5 => (file not found)
libm.so.2 => /lib/64/libm.so.2
libgcc_s.so.1 => (file not found)
libc.so.1 => /lib/64/libc.so.1
libaio.so.1 => /lib/64/libaio.so.1
libmd.so.1 => /lib/64/libmd.so.1
/platform/SUNW,Netra-T12/lib/sparcv9/libc_psr.so.1
/platform/SUNW,Netra-T12/lib/sparcv9/libmd_psr.so.1
And now the older binary which was still compiled in a "true" Solaris 8 environment:
ldd myapp
libm.so.1 => /lib/64/libm.so.1
librt.so.1 => /lib/64/librt.so.1
libpthread.so.1 => /lib/64/libpthread.so.1
libc.so.1 => /lib/64/libc.so.1
libaio.so.1 => /lib/64/libaio.so.1
libmd.so.1 => /lib/64/libmd.so.1
libm.so.2 => /lib/64/libm.so.2
/platform/SUNW,Netra-T12/lib/sparcv9/libc_psr.so.1
/platform/SUNW,Netra-T12/lib/sparcv9/libmd_psr.so.1
The only difference I know of (except for the completely different OS environment) is that the gcc call they used to use in Solaris 8 didn't work in Solaris 10. When trying to compile a very simple C++ program we ran into a lot of errors (the example code is widely used in multiple variations across the net):
$ cat easy.cpp
#include <iostream>
int main()
{
std::cout << "Welcome to the wonderful world of C++!!!\n";
return 0;
}
The result of using "gcc" as the command (gcc32 is actually a link to gcc in our environment, as g++32 links to g++ (with the appropriate version 3.2.1)):
$ gcc32 -m64 -o easy easy.cpp
/var/tmp//ccWzG0Lj.o: In function `main':
/var/tmp//ccWzG0Lj.o(.text+0x4): undefined reference to `std::cout'
/var/tmp//ccWzG0Lj.o(.text+0x8): undefined reference to `std::cout'
/var/tmp//ccWzG0Lj.o(.text+0xc): undefined reference to `std::cout'
/var/tmp//ccWzG0Lj.o(.text+0x18): undefined reference to `std::cout'
/var/tmp//ccWzG0Lj.o(.text+0x34): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/var/tmp//ccWzG0Lj.o: In function `__static_initialization_and_destruction_0(int, int)':
/var/tmp//ccWzG0Lj.o(.text+0xa4): undefined reference to `std::ios_base::Init::Init[in-charge]()'
/var/tmp//ccWzG0Lj.o(.text+0xec): undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/var/tmp//ccWzG0Lj.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
When I called g++ directly, the program compiled with only one warning:
$ g++32 -m64 -o easy easy.cpp
/home/user/tools/bin/ld: warning: libm.so.1, needed by /home/user/tools/gcc32/lib/gcc-lib/sparc-sun-solaris2.8/3.2.1/../../../sparcv9/libstdc++.so, may conflict with libm.so.2
When I tried to run it I first also encountered the missing libstdc++.so.5 library but being on the development machine a tweak of LD_LIBRARY_PATH solved this problem.
However: the target production machines don't have libstdc++.so.5 installed (they have version 6) and although it might be possible to install an extra gcclib package the question remains: why does the call with g++ link to those two extra libraries while the call with gcc doesn't - or, rephrased: how can I compile the binary so it doesn't need the extra libraries, as it didn't need them before, when it was compiled in Solaris 8?
Thanks very much in advance for your patience (it has become quite a long text) and any hint is most appreciated.
Kind regards,
Henning

undefined reference when trying to load a custom mysql plugin - how to debug?

I am trying to write my own MySQL storage engine which uses a key-value store as a back-end.
I wrote now my first version which implements the mandatory parts and I am able to compile, link, and install my MySQL source instance. After doing so I tried to load my new plugin with the following command in the mysql console:
install plugin ramcloud soname 'ha_ramcloud.so';
The error I get is the following:
ERROR 1126 (HY000): Can't open shared library '/usr/local/mysql/lib/plugin/ha_ramcloud.so' (errno: 13 undefined symbol: _ZNSt8_Rb_treeImmSt9_IdentityImESt4lessImESaImEE8_M_eraseEPSt13_Rb_tree_nodeImE)
Now I have no idea how to debug this problem. The client library from the key-value store uses the -std=c++0x compiler flag and I start to think that this could be part of the problem. But when I check with ldd, my storage engine links against the same libstdc++ version as the other engines delivered with mysql which can be loaded without any problems.
Are there any tricks in how to figure out where this problem comes from?
EDIT: The symbol which does not get found is
std::_Rb_tree<unsigned long, unsigned long, std::_Identity<unsigned long>, std::less<unsigned long>, std::allocator<unsigned long> >::_M_erase(std::_Rb_tree_node<unsigned long>*)
This looks like something from libstdc++ (STL) and is probably from my use of std::set. How can this happen?
It was a stupid error: the MySQL build system uses the -fno-implicit-templates option. Removing this for my plugin solved the problem (I could also make an explicit instance, but since I program only a prototype this should be ok).