如何使用standalone toolchain移植含STL与线程的程序

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]$ 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 -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/hi1234
hello world
this is a string type
thread begin
thread end
#
# cat /mnt/sdcard/345tt

abcedfg#  

 
OK, I'm done here.
So , I need to write articles about configure and Makefile.

 EOF

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值