简体   繁体   中英

How can I link both C and C++ code, along with C and C++ runtime libraries (including STL) on android ndk?

I have a large code base with mixed C and C++ code. It is built into libraries, and then ultimately to an executable that runs on android based devices. This is an "external build system" that does not use gradle. After all compilation and libraries are built, the final link command is something like

armv7a-linux-androideabi30-clang++ -pie -static-libstdc++ -o a.out -L...-lmylib1 -lmylib2 -lm -llog

When the program is run, I get "cannot locate symbol fread_unlocked". When I look at the expansion of that link command under the hood using -###, clang++ automatically adds -lc and -lgcc among other libs (otherwise, I would add them myself).

Alternately, I have tried linking the c++ stdlib (the stl one, libc++) into the C linker

armv7a-linux-androideabi30-clang -o a.out -L...-lmylib1 -lmylib2 -lm -llog -lc++

When the program is executed, I get "cannot find libc++_shared.so". I don't want to copy any shared libs along with my app, so I prefer the c++ lib to be statically linked, but I don't see a way to do that with clang. If I try to statically link the entire thing with -static, then it cannot find static versions of liblog among others. And I confirmed that there is no liblog.a in the latest ndk (only liblog.so).

So, I believe my basic need is to link a mixture of C and C++ code, along with C and C++ runtimes, and have no shared lib dependencies on target.

I was building for API 30 and running on an older target. I changed the link command to armv7a-linux-androideabi23-clang++ and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM