简体   繁体   English

在 Windows 7 上从 Java 启动 CYGWIN 构建的可执行文件失败,并显示“加载共享库时出错:?:没有这样的文件或目录”

[英]Launching CYGWIN-built executable from Java on Windows 7 fails with "error while loading shared libraries: ?: No such file or directory"

The code in question has worked in more or less the exact same configuration on earlier releases of Windows, however, it is not known to have run on Windows 7 YET.有问题的代码在 Windows 的早期版本中或多或少地以完全相同的配置工作,但是,不知道它是否在 Windows 7 YET 上运行。 That's what I need to solve now.这就是我现在需要解决的。

Briefly, some C code performs some configuration and security checks before launching a java program, passing some data that would be neigh-into-impossible to do easily in Java. The Java in turn, at the appropriate time launches the same C code which then itself launches a different Java program.简而言之,一些 C 代码在启动 java 程序之前执行一些配置和安全检查,传递一些在 Java 中几乎不可能轻松完成的数据。Java 依次在适当的时间启动相同的 C 代码,然后本身会启动一个不同的 Java 程序。 The second program launch needs to be completely independent, (think nohup) hence the second launch.第二个程序启动需要完全独立,(想想 nohup)因此是第二个启动。

What's happening now is that the C program launches the Java program in the ordinary way, but when the Java tries to launch the C program, it errors out like this:现在发生的事情是 C 程序以普通方式启动 Java 程序,但是当 Java 尝试启动 C 程序时,它会出现如下错误:

/cygdrive/c/opt/ST/v3.3/bin/ST.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory /cygdrive/c/opt/ST/v3.3/bin/ST.exe:加载共享库时出错:?:无法打开共享 object 文件:没有这样的文件或目录

Because Windows has been such a bear over the years, the C code is written in the posix environment of Cygwin, but all it really does is ordinary C types of things (nothing about it is unique to Cygwin and, indeed, in the past it has been built with Microsoft's development tools, but that environ is not available at present).因为Windows这么多年来一直这么熊,所以C的代码是在Cygwin的posix环境下写的,但它真正做的只是普通的C类型的东西(没有什么是Cygwin独有的,的确,过去它已经用微软的开发工具构建,但目前没有那个环境)。 The Cygwin environ adds a lot of other great benefits, like command-line management of services (cygrunsrv) and a full-on 'nix-like environment (bash, etc). Cygwin 环境增加了许多其他好处,例如服务的命令行管理 (cygrunsrv) 和完整的“nix 类环境”(bash 等)。 In fact, because Windows has changed how one launches a program from Java so many times, Cygwin helps standardize the Java launch code.事实上,由于 Windows 多次改变了从 Java 启动程序的方式,Cygwin 帮助标准化了 Java 启动代码。 Here's an excerpt:这是摘录:

  if (ClientOS.indexOf("Windows") != -1)
  {
     if (ClientOS.equals("Windows 95"))
     {
        cmd = "command.com /C ";
     } else if (ClientOS.equals("Windows 98"))
     {
        cmd = "command.com /C ";
        //cmd = "cmd.exe /C ";
     } else if (ClientOS.equals("Windows NT"))
     {
        cmd = "cmd.exe /C ";
     } else if (ClientOS.equals("Windows 2000"))
     {
        cmd = "cmd.exe /C ";
     } else if (ClientOS.equals("Windows XP"))
     {
        cmd = "cmd.exe /C ";
     } else {
        cmd = "cmd.exe /C ";
     }
     if (cygwin)
     {
        cmd += Shell+" '"+Command+"'";
     } else {
        cmd += Command;
     }
  } else {
     cmd = Command;
  }

(Yes, the if structure could be better optimized.) (是的,可以更好地优化 if 结构。)

In this case, "Shell" equals:在这种情况下,“Shell”等于:

Shell=C:/cygwin/bin/bash -c

And, there's a test program to ensure the above and supporting code works OK - it runs a bit of shell program and ensures it got back what it thought it should.并且,有一个测试程序可确保上述代码和支持代码正常工作 - 它运行了一些 shell 程序并确保它恢复了它认为应该的状态。 It says:它说:

Checking the ability to run a program using a shell... Yes, shell programs work fine.检查使用 shell 运行程序的能力...是的,shell 程序运行良好。

The final contents of cmd look something like this: cmd 的最终内容如下所示:

cmd.exe /C C:/cygwin/bin/bash -c '/cygdrive/c/opt/ST/v3.3/bin/ST.exe' cmd.exe /C C:/cygwin/bin/bash -c '/cygdrive/c/opt/ST/v3.3/bin/ST.exe'

WHAT I SUSPECT:我怀疑的是:

I suspect what's going on is that the Cygwin1.DLL file isn't being found properly.我怀疑发生的事情是未正确找到 Cygwin1.DLL 文件。 It lives in C:/cygwin/bin/cygwin1.dll它位于 C:/cygwin/bin/cygwin1.dll

NOTE THAT both the system-level PATH and the Cygwin PATH include the path to the cygwin.dll files.注意,系统级路径和 Cygwin 路径都包含 cygwin.dll 文件的路径。 Moving a copy of cygwin1.dll to the bin directory where the target executable lives didn't work either.将 cygwin1.dll 的副本移动到目标可执行文件所在的 bin 目录也不起作用。

Would LD_LIBRARY_PATH lend any help here? LD_LIBRARY_PATH 会在这里提供任何帮助吗? If so, any idea how it is to be set?如果是这样,知道如何设置吗?

Other ideas?其他想法?

Thanks.谢谢。

C:/cygwin/bin/bash -c '/cygdrive/c/opt/ST/v3.3/bin/ST.exe'

This won't work because your working directory is where you reside when you executed this command.这不会起作用,因为您的工作目录是您执行此命令时所在的位置。 You will have to copy the cygwin dependent dlls to the directory you execute this from.您必须将依赖于 cygwin 的 dll 复制到执行此操作的目录中。 Othwerwise, you will have to place the cygwin bin directory in your system PATH variable, not sure you want to do that, can cause dll hell.否则,您必须将 cygwin bin 目录放在系统 PATH 变量中,不确定是否要这样做,可能会导致 dll 地狱。

Also, if you're using anything in your profile, you need to add --login parameter to bash:此外,如果您在个人资料中使用任何内容,则需要将 --login 参数添加到 bash:

bash --login -c

Also, print the final command out at the end, before you spawn the process:另外,在生成进程之前,在最后打印出最终命令:

printf('%s\n',cmd)

Just to be sure it's exactly what you want.只是为了确保它正是您想要的。

You may also run the program with strace, if you're unsure about the dlls being referenced.如果您不确定所引用的 dll,您也可以使用 strace 运行该程序。

Several ways.几种方式。

cygwin1.dll needs to be in %WINDIR%\system32 or equivalent. cygwin1.dll 需要位于 %WINDIR%\system32 或同等位置。

or要么

you modify the PATH variable to add the path to cygwin1.dll in the caller's environment.您修改 PATH 变量以在调用方环境中添加到 cygwin1.dll 的路径。

or要么

you call a.bat file that sets the environment before you call the cygwin built exe.在调用 cygwin 构建的 exe 之前,调用设置环境的.bat 文件。

or要么

you build a standalone version of the.exe (ie no cygwin dependency).你构建了一个独立版本的.exe(即没有cygwin依赖)。

暂无
暂无

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

相关问题 java:加载共享库时出错:libjl i.so:无法打开共享库文件:没有这样的文件或目录 - java: error while loading shared libraries: libjl i.so: cannot open shared object file: No such file or directory 加载共享库时出错; 无法打开共享对象文件:没有这样的文件或目录 - Error while loading shared libraries; cannot open shared object file: No such file or directory 加载共享库时出错:libX11.so.6:无法打开共享对象文件:Linux docker容器中没有此类文件或目录 - error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory in linux docker container 加载共享库时出错:Java中的libjli.so - Error while loading shared libraries: libjli.so in Java jar:加载共享库时出错:libjli.so [如何手动安装Java 6] - jar: error while loading shared libraries: libjli.so [How to manually install Java 6] 加载共享库时出错:libcrfpp.so.0 - error while loading shared libraries: libcrfpp.so.0 从Java启动的JRuby脚本加载JNI库失败 - Loading JNI libraries from JRuby script started from Java fails 加载Java VM时出现Windows错误2 - Windows error 2 occured while loading the Java VM 从JAVA启动批处理文件不适用于具有空格的目录路径 - Launching batch file from JAVA not working for directory path having spaces 加载共享库 libstdc++.so.6 时出错:没有这样的文件或目录(需要) - Error loading shared library libstdc++.so.6: No such file or directory (needed by)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM