如何使用standalone toolchain移植含STL与线程的程序
2012-09-26 17:40
537 查看
I try to build my program without jni ndk-build , but by a standalne arm-kind cross compliers way .
However ,after I write a simple sample , using STL and thread function with my own Makefile , and I do make command,
I encount all kind of weird program .
error 0: in a dynamic library way
[dengwei@localhost ~]$ make
arm-marvell-linux-gnueabi-g++ hi.cpp -o hi1234 -lpthread
[dengwei@localhost platform-tools]$ adb push ~/hi1234 /data/
[dengwei@localhost platform-tools]$ adb shell
# /data/hi1234
/data/hi1234: not found
analyse: libpthread.so may not found.
error 1: in a static library way
arm-marvell-linux-gnueabi-g++ -static hi.cpp -o hi1234 -lpthread
# /data/hi1234
terminate called after throwing an instance of '__gnu_cxx::__concurrence_broadcast_error'
what(): __gnu_cxx::__concurrence_broadcast_error
[1] Aborted /data/hi1234
analyse: libpthread.a doesn't may real match and other unknow reason
some say add "-Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc " in complie command will fix the problem ,but it does NOT work for me.
I change cross compliers to use standalone cross compliers : ref to $(NDK)/docs/STANDALONE-TOOLCHAIN.html
==============thread succeed this time===============================
$make
arm-linux-androideabi-g++ hi.o -static -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a -lstdc++ -DTHREAD -o hi1234
---------------result:------------------------------
# ./hi1234
hello world
thread begin
thread end
#
# cat /mnt/sdcard/345tt
abcedfg#
But STL still can NOT work. I found solution here in stackoverflow
"I think "APP_STL:=stlport_static" must be in Application.mk file.
Create a "Application.mk" file and write "APP_STL:=stlport_static" in it."
#include <cerrno>
#include <cstddef>
#include <iostream>
using namespace std;
int main(void)
{
string sss;
const char *hs= "this is a string";
sss.assign(hs, strlen(hs));
printf("%s\n", sss.c_str());
return 0;
}
[dengwei@localhost jni]$ ndk-build
Compile++ thumb : test-libstl <= test-libstl.cpp
Executable : test-libstl
Install : test-libstl => libs/armeabi/test-libstl
But this sample is still build in JNI ,NOT a standalone version .
I begin to find I did NOT fully unstand configure and Makefile
Here comes the solution:
$export PATH=/home/dengwei/standalone-toolchain/bin:$PATH && export CC=arm-linux-androideabi-gcc && export CXX=arm-linux-androideabi-g++
Makefile:
STANDALONE_PATH=/home/dengwei/standalone-toolchain
LDFLAGS= -static
LIBS+= -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a
LIBS+= -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a
INCLUDES= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/
INCLUDES+= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi
CXXFLAGS= -DTHREAD
CXXFLAGS+= -DUSE_STL
CXXFLAGS+= $(INCLUDES)
#CXXFLAGS+= -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc
OBJS=hi.o
PROGRAM=hi1234
$(PROGRAM):$(OBJS)
$(CXX) $(OBJS) $(LDFLAGS) $(LIBS) $(CXXFLAGS) -o $@
clean:
rm $(OBJS) -rf
rm $(PROGRAM) -rf
INCLUDES= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/
INCLUDES+= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi
above are using for find iostream and bit/c++_config.h
LIBS+= -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a
LIBS+= -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a
above are using for static complie
==============stl succeed this time===============================
[dengwei@localhost testNSA]$ makearm-linux-androideabi-g++ hi.o -static -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a -DTHREAD -DUSE_STL -I /home/dengwei/standalone-toolchain/arm-linux-androideabi/include/c++/4.6/ -I /home/dengwei/standalone-toolchain/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi -o hi1234# /data/hi1234hello worldthis is a string typethread beginthread end## cat /mnt/sdcard/345ttabcedfg#
OK, I'm done here.
So , I need to write articles about configure and Makefile.
EOF
However ,after I write a simple sample , using STL and thread function with my own Makefile , and I do make command,
I encount all kind of weird program .
error 0: in a dynamic library way
[dengwei@localhost ~]$ make
arm-marvell-linux-gnueabi-g++ hi.cpp -o hi1234 -lpthread
[dengwei@localhost platform-tools]$ adb push ~/hi1234 /data/
[dengwei@localhost platform-tools]$ adb shell
# /data/hi1234
/data/hi1234: not found
analyse: libpthread.so may not found.
error 1: in a static library way
arm-marvell-linux-gnueabi-g++ -static hi.cpp -o hi1234 -lpthread
# /data/hi1234
terminate called after throwing an instance of '__gnu_cxx::__concurrence_broadcast_error'
what(): __gnu_cxx::__concurrence_broadcast_error
[1] Aborted /data/hi1234
analyse: libpthread.a doesn't may real match and other unknow reason
some say add "-Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc " in complie command will fix the problem ,but it does NOT work for me.
I change cross compliers to use standalone cross compliers : ref to $(NDK)/docs/STANDALONE-TOOLCHAIN.html
==============thread succeed this time===============================
$make
arm-linux-androideabi-g++ hi.o -static -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a -lstdc++ -DTHREAD -o hi1234
---------------result:------------------------------
# ./hi1234
hello world
thread begin
thread end
#
# cat /mnt/sdcard/345tt
abcedfg#
But STL still can NOT work. I found solution here in stackoverflow
"I think "APP_STL:=stlport_static" must be in Application.mk file.
Create a "Application.mk" file and write "APP_STL:=stlport_static" in it."
#include <cerrno>
#include <cstddef>
#include <iostream>
using namespace std;
int main(void)
{
string sss;
const char *hs= "this is a string";
sss.assign(hs, strlen(hs));
printf("%s\n", sss.c_str());
return 0;
}
[dengwei@localhost jni]$ ndk-build
Compile++ thumb : test-libstl <= test-libstl.cpp
Executable : test-libstl
Install : test-libstl => libs/armeabi/test-libstl
But this sample is still build in JNI ,NOT a standalone version .
I begin to find I did NOT fully unstand configure and Makefile
Here comes the solution:
$export PATH=/home/dengwei/standalone-toolchain/bin:$PATH && export CC=arm-linux-androideabi-gcc && export CXX=arm-linux-androideabi-g++
Makefile:
STANDALONE_PATH=/home/dengwei/standalone-toolchain
LDFLAGS= -static
LIBS+= -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a
LIBS+= -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a
INCLUDES= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/
INCLUDES+= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi
CXXFLAGS= -DTHREAD
CXXFLAGS+= -DUSE_STL
CXXFLAGS+= $(INCLUDES)
#CXXFLAGS+= -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -lc
OBJS=hi.o
PROGRAM=hi1234
$(PROGRAM):$(OBJS)
$(CXX) $(OBJS) $(LDFLAGS) $(LIBS) $(CXXFLAGS) -o $@
clean:
rm $(OBJS) -rf
rm $(PROGRAM) -rf
INCLUDES= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/
INCLUDES+= -I $(STANDALONE_PATH)/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi
above are using for find iostream and bit/c++_config.h
LIBS+= -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a
LIBS+= -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a
above are using for static complie
==============stl succeed this time===============================
[dengwei@localhost testNSA]$ makearm-linux-androideabi-g++ hi.o -static -L /home/dengwei/standalone-toolchain/sysroot/usr/lib/libthread_db.a -L /home/dengwei/standalone-toolchain/arm-linux-androideabi/lib/libsupc++.a -DTHREAD -DUSE_STL -I /home/dengwei/standalone-toolchain/arm-linux-androideabi/include/c++/4.6/ -I /home/dengwei/standalone-toolchain/arm-linux-androideabi/include/c++/4.6/arm-linux-androideabi -o hi1234# /data/hi1234hello worldthis is a string typethread beginthread end## cat /mnt/sdcard/345ttabcedfg#
OK, I'm done here.
So , I need to write articles about configure and Makefile.
EOF
相关文章推荐
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- 如何让 Qt 的程序使用 Sleep(主线程没有Sleep函数,但线程可用自带的保护函数Sleep)
- JAVA Eclipse中的Android程序如何使用线程
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- Android NDK 工具链的使用方法(Standalone Toolchain)
- JAVA Eclipse中的Android程序如何使用线程
- 7.VC(custom)-解决DLL和主调程序的资源冲突及如何使用Dll的资源
- 举例说明如何实现使用线程来实现UC浏览器的等待页面的效果
- C#中如何使用断点操作调试程序
- 如何使用InstallShield8.0制作自己的安装程序
- 如何在64位的linux系统上使用汇编和C语言混合编程-32汇编移植64位系统
- 如何正確的使用迴圈(使用for_each)? (C/C++) (STL) (template)
- 如何使用java程序实现windows锁屏
- 如何使用remove_copy_if() algorithm? (C/C++) (STL)