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

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.

Related

Suggestions to compile the program fung-calc

Im trying to compile the program called fungcalc, its a graph software which the last version was made on 2003, it was designed to run in kde 3.5 (qt3).
Now the steps that I did was to install the qt3 libs, and the required componens missing based in the
./configure --disable-kde-app
this argument remove the support for kde (and the need for its libs too).
When compiling it stops almost at the end (since many .so where compiled but not the main executable)with the next output
/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[4]: *** [Makefile:412: libfungcalc.la] Error 1
make[4]: Leaving directory '/fung-calc-1.3.2b/src/libfungcalc'
With the same error for the lines 277,337,495,505 of the Makefile.
So what suggestion could be so I can start to roam the entire code?
The entire Makefile is here
I don't know if this runs on 64 bits (but I suppose it does).

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

CPP MQTT Broker code not working

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.

Can't create QT postgresql plugin for Symbian device

I'm trying to create postgresql plugin for Symbian device but I can't compile it. I'm working on Windows 7 64bit.
I did everything according to this article: http://doc.qt.io/archives/qt-4.7/sql-driver.html#qpsql
C:\QtSDK\QtSources\4.8.1\src\plugins\sqldrivers\psql>qmake "INCLUDEPATH+=C:\Program Files (x86)\PostgreSQL\8.3\include" "LIBS+=C:\Program Files (x86)\PostgreSQL\8.3\lib\libpq.lib" psql.pro
WARNING: (internal):1: Unescaped backslashes are deprecated.
So, it looked OK. Then...
C:\...drivers\psql>C:\QtSDK\Symbian\tools\sbs\win32\mingw\bin\make debug-gcce
sbs -c arm.v5.udeb.gcce4_4_1
python.exe is not recognized as an internal or external command, operable program or batch file.
make: *** [debug-gcce] Error 9009
I noticed, that sbs_home was set to python directory but it was not in the path, then the make could not find the script raptor_start.py:
C:\...drivers\psql>echo %sbs_home%
C:\QtSDK\Symbian\tools\sbs\win32\python27
C:\...drivers\psql>set path=%path%;%sbs_home%
C:\...drivers\psql>C:\QtSDK\Symbian\tools\sbs\win32\mingw\bin\make debug-gcce
sbs -c arm.v5.udeb.gcce4_4_1
python.exe: can't open file C:\QtSDK\Symbian\tools\sbs\win32\python27\python\raptor_start.py': [Errno 2] No such file or directory
make: *** [debug-gcce] Error 2
C:\...drivers\psql>set sbs_home=C:\QtSDK\Symbian\tools\sbs
so, when I started compiling I got this error:
C:/QtSDK/Symbian/SDKs/Symbian3Qt474/epoc32/include/stdapis/stlportv5/stl/_istream.c:650: warning: suggest parentheses around '&&' within '||' target : epoc32\release\armv5\udeb\qsqlpsql.dll [arm.v5.udeb.gcce4_4_1]
FAILED linkandpostlink for arm.v5.udeb.gcce4_4_1: epoc32\release\armv5\udeb\qsqlpsql.dll
mmp: qsqlpsql_dll.mmp
c:/qtsdk/symbian/tools/gcce4/bin/../lib/gcc/arm-none-symbianelf/4.4.1/../../../../arm-none-symbianelf/bin/ld.exe: warning: C:/QtSDK/Symbian/SDKs/Symbian3Qt474/epoc32/release/armv5/udeb/usrt3_1.lib(ucppinit.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
C:/QtSDK/Symbian/SDKs/Symbian3Qt474/epoc32/build/psql/c_8d95259b570e1766/qsqlpsql_dll/armv5/udeb/qsql_psql.o: In function `qMakeError': C:/QtSDK/QtSources/4.8.1/src/sql/drivers/psql/qsql_psql.cpp:175: undefined reference to `PQerrorMessage'
....many undefined references...
C:/QtSDK/QtSources/4.8.1/src/sql/drivers/psql/qsql_psql.cpp:117: undefined reference to `PQfreemem'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [C:/QtSDK/Symbian/SDKs/Symbian3Qt474/epoc32/release/armv5/udeb/qsqlpsql.dll] Error 1
sbs: error: The make-engine exited with errors.
sbs : warnings: 3
sbs : errors: 2
built 'arm.v5.udeb.gcce4_4_1'
Run time 5 seconds
sbs: build log in C:\QtSDK\Symbian\SDKs\Symbian3Qt474\epoc32\build\Makefile.2012-06-26-15-03-12.78-2996.log
make: *** [debug-gcce] Error 1
Has anybody idea, what with it?
You are trying to build an Symbian/ARM application using precompiled binary postgresql client library for Windows. This won't ever work. The instructions you refer to only show how to build for OS X, Unix and Mac targets natively. You're cross compiling for Symbian.
You'd first need to obtain a binary version of the postgresql client library compiled for Symbian. It might exist out there, or you may need to compile it yourself. I don't think that the library supports Symbian as a target, and I couldn't readily find any Symbian ports for download. You may be out of luck for a trivial solution. A port might not be entirely out of the question, though -- perhaps the platform-specific code is localized enough.