简体   繁体   English

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

[英]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.我有一个混合 C 和 C++ 代码的大型代码库。 It is built into libraries, and then ultimately to an executable that runs on android based devices.它被内置到库中,然后最终成为在基于 android 的设备上运行的可执行文件。 This is an "external build system" that does not use gradle.这是一个不使用 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".当程序运行时,我得到“找不到符号 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).当我使用 -### 查看该链接命令的扩展时,clang++ 会自动在其他库中添加 -lc 和 -lgcc(否则,我会自己添加它们)。

Alternately, I have tried linking the c++ stdlib (the stl one, libc++) into the C linker或者,我尝试将 c++ 标准库(stl 之一,libc++)链接到 C Z3175872608434073C Z3175873773

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".执行程序时,我得到“找不到 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.我不想将任何共享库与我的应用程序一起复制,因此我更喜欢静态链接 c++ 库,但我看不到使用 clang 的方法。 If I try to statically link the entire thing with -static, then it cannot find static versions of liblog among others.如果我尝试使用 -static 静态链接整个事物,则它找不到 static 版本的 liblog 等。 And I confirmed that there is no liblog.a in the latest ndk (only liblog.so).而且我确认最新的ndk中没有liblog.a(只有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. 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.我正在为 API 30 构建并在较旧的目标上运行。 I changed the link command to armv7a-linux-androideabi23-clang++ and it worked.我将链接命令更改为 armv7a-linux-androideabi23-clang++ 并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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