- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
尝试运行简单的 HelloWorld Unix 可执行文件时:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
}
(通过 g++ HelloWorld.cpp -o HelloWorld
编译(在 Mac 上)。该程序通过使用 ./HelloWorld 并让它在 Java 环境中运行来在我的 Mac 上运行:
(HelloWorld.java -> working)
public class HelloWorld
{
public static void main(String args[])
{
String[] command = new String[]{"/system/bin/chmod", "744",
"/Developer/Java/HelloWorld" };
execute(command);
command = new String[]{"./HelloWorld"};
execute(command);
}
public static void execute(String...command)
{
StringBuilder log = new StringBuilder();
try
{
BufferedReader br;
String line;
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
Process proc = builder.start();
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ( (line = br.readLine()) != null)
System.out.println(line + "\n");
}
catch (IOException e) {
log.append("General IOException:\n" + e.getMessage() + "\n");
}
catch (InterruptedException e) {
log.append("Error:\n" + e.getMessage() + "\n");
}
}
}
在 Android 应用程序的 java 代码中,我首先将可执行文件复制到 getBaseContext().getDataDir()
,效果很好。要更改权限,我使用以下命令:
command = new String[]{"/system/bin/chmod", "744",
getAssetsPath() + "/HelloWorld" };
execute(pv, command);
并尝试通过以下方式运行程序:
command = new String[]{"." + getAssetsPath() + "/HelloWorld"};
terminal(tv, command);
请注意,我使用以下函数:
public File getAssetsDir() {
return getBaseContext().getDataDir();
}
public String getAssetsPath() {
return getAssetsDir().getAbsolutePath();
}
public void execute(TextView tv, String...command)
{
tv.setText("Starting Terminal.\n");
StringBuilder log = new StringBuilder();
try
{
BufferedReader br;
String line;
ProcessBuilder builder = new ProcessBuilder(command);
builder.redirectErrorStream(true);
Process proc = builder.start();
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ( (line = br.readLine()) != null)
log.append(line + "\n");
}
catch (IOException e) {
log.append("General IOException:\n" + e.getMessage() + "\n");
}
catch (InterruptedException e) {
log.append("Error:\n" + e.getMessage() + "\n");
}
tv.setText(log.toString());
}
正如已经说过的,这将导致 TextView 内出现以下错误(在 Pixel_XL_API_25 上测试):
syntax error: '__TEXT' unexpected
希望您能帮我找出问题的原因。提前致谢。
编辑:如果你想知道为什么我想使用 Unix 可执行文件来完成如此简单的事情:这只是为了测试。实际上,我想运行其他更复杂的程序/库,这些程序/库很难通过 ndk 使用,因为这个库没有 cmake,只有“正常”make。
最佳答案
答案是,该编译器不是正确的编译器。我想,如果你想在另一台设备上运行它,你必须在那里编译它或使用一些交叉编译器。
现在的问题是:哪种编译器可以工作?我发现了这个建议(How to compile and run a C/C++ program on the Android system):
arm-linux-gnueabi-g++ -static -march=armv7-a HelloWorld.c -o HelloWorld
但这在这个特定的星座中不起作用。
关于java - Android 尝试运行 unix 可执行文件 : syntax error: '__TEXT' unexpected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44548009/
升级到 Xcode 4.4 后,当我尝试在 iPhone 或 iPad 上运行我的(通用)应用程序时,我遇到了这个烦人的链接器错误。如果我在 iOS 模拟器上运行它,我没有问题... 我尝试添加 ar
使用 gold 和其他链接器,可以让链接器使用链接器脚本将 .text 部分的开始/结尾作为常量写入二进制文件,例如 PROVIDE_HIDDEN(linker_script_start_of_tex
我已经尝试了很多来最终让它工作,但它仍然无法工作。我试图更改 __TEXT 部分中的一些变量,默认情况下它是只读的,例如更改 cryptid(和其他内容) 它有点像以前工作,回到 32 位设备上。但是
在 OS X 上使用 MacPorts GCC 并通过 -Wa,-q 使用 Clang 集成汇编器时,汇编器会为每个文件生成一个警告流。下面显示了警告的示例(其中太多,Stack Overflow 编
为了找到我的 mach-o 可执行文件的 __TEXT 和 __DATA 的 dyld 地址映射,我设置了环境变量 DYLD_PRINT_SEGMENTS=1。这将记录在可执行文件映射到内存中的控制台
如何将部分从 __TEXT 段中移出并移入 mach-o 二进制文件的新段中?我问的原因是我试图让我的 iPhone 应用程序更小,并且 iOS App Store 在压缩之前加密了它的 __TEXT
我正在尝试从 iPhone Mach-O 二进制文件中读取常量(或初始化)字符串。我知道 3 个相关的 segment.sections 是 _TEXT._cstring _TEXT._ustring
我正在使用 -sectcreate __TEXT 链接器标志将可执行文件与 plist 链接起来。这样做的原因主要是使用了 SMJobBless() 方法。但我需要阅读从另一个应用程序链接的 plis
某些程序(甚至操作系统本身)是否出于某种原因更改了可执行文件的 __TEXT 段的内容? 注意:在这里,我指的是“__TEXT”部分,而不是“__text”部分。 换句话说:我能否依靠我的可执行文件的
尝试运行简单的 HelloWorld Unix 可执行文件时: #include using namespace std; int main() { cout working) publi
我是一名优秀的程序员,十分优秀!