C++ shared library compiled with g++

443 views
Skip to first unread message

Nicholas Terry

unread,
Jul 12, 2012, 11:36:47 PM7/12/12
to andro...@googlegroups.com
So i compiled a shared lib with g++ written in c++. It uses the following headers:

#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <sys/ioctl.h>

You can get the source code HERE

I use POSIX compliant method calls and types. Will a lib that is not compiled with the ndk work with android?

Also, if i have to use the the NDK, is this the correct way to specify my makefile?

LOCAL_PATH := /home/nick/.projects/39dll-4-linux/jni
include $(CLEAR_VARS)

LOCAL_MODULE    := 39dll-4-linux
LOCAL_SRC_FILES := buffer.cpp, list.cpp, main.cpp, md5.cpp, socket.cpp, tools.cpp
INCLUDE_HEADERS        := sys/socket.h,  sys/types.h, netinet/in.h, arpa/inet.h, netinet/tcp.h, stdio.h, stdlib.h, string.h, iostream, sys/ioctl.h

include $(BUILD_SHARED_LIBRARY) 



Do you separate the individual libs with commas, semicolons, or what?

David Turner

unread,
Jul 13, 2012, 5:32:14 AM7/13/12
to andro...@googlegroups.com
On Fri, Jul 13, 2012 at 5:36 AM, Nicholas Terry <nick.i...@gmail.com> wrote:

I use POSIX compliant method calls and types. Will a lib that is not compiled with the ndk work with android?


Probably not, the Bionic and GLibc ABIs (binary interfaces) are very different and incompatible, so you probably won't be able to link a library built with a non-Android toolchain into an Android project (assuming you're targetting the same CPU architecture and ABI too).
 
Also, if i have to use the the NDK, is this the correct way to specify my makefile?

LOCAL_PATH := /home/nick/.projects/39dll-4-linux/jni
include $(CLEAR_VARS)

LOCAL_MODULE    := 39dll-4-linux
LOCAL_SRC_FILES := buffer.cpp, list.cpp, main.cpp, md5.cpp, socket.cpp, tools.cpp
INCLUDE_HEADERS        := sys/socket.h,  sys/types.h, netinet/in.h, arpa/inet.h, netinet/tcp.h, stdio.h, stdlib.h, string.h, iostream, sys/ioctl.h

include $(BUILD_SHARED_LIBRARY) 


Better use "LOCAL_PATH := $(call my-dir)" to avoid hard-coding stuff in your Android.mk (unless you auto-generate it).
Don't use commas in LOCAL_SRC_FILES, spaces are the only supported separator.
INCLUDE_HEADERS will completely ignored and is not necessary. The C library headers (e.g. <sys/socket.h>) are automatically available when you build with either ndk-build or the standalone NDK toolchain.

Apart from that, this should be ok to build a shared library. It main.cpp actually contains a main() entry point, you will want BUILD_EXECUTABLE, but the result cannot be packaged into  an .apk (but can be installed manually to a device with "adb push" then run with "adb shell").



Do you separate the individual libs with commas, semicolons, or what?

You should really read the NDK documentation under docs/, see docs/OVERVIEW.html, docs/ANDROID-MK.html, docs/APPLICATION-MK.html in particular. 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/nqJvje4MyIUJ.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.

Nicholas Terry

unread,
Jul 13, 2012, 11:55:00 AM7/13/12
to andro...@googlegroups.com
Awesome, I Appreciate the answers.

I did eventually figure out the separator while google searching other things.

One other question:

I am getting the following error when trying to build my project:

$ /usr/bin/android-ndk-r8/ndk-build
make: /usr/bin/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
make: /usr/bin/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc: Command not found
Compile++ thumb  : 39dll-4-linux <= buffer.cpp
make: /usr/bin/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++: Command not found
make: *** [/home/nick/.projects/39dll-4-linux/obj/local/armeabi/objs/39dll-4-linux/buffer.o] Error 127


I get the same error with example projects from various sources. Any ideas as how to fix this? I've done extensive google searching with no useful results...

 
To unsubscribe from this group, send email to android-ndk+unsubscribe@googlegroups.com.

Nicholas Terry

unread,
Jul 15, 2012, 9:20:29 PM7/15/12
to andro...@googlegroups.com
Figured it out. Needed to install the android sdk and add it to my path.
Reply all
Reply to author
Forward
0 new messages