如何使用libssh运行makefile
How to run makefile with libssh?
我的libssh(libssh.org(有问题。我需要在远程服务器上运行一个makefile。我使用命令"channel_request_exec":
int SSHExecCmd (void(* MessSender)(char* CurMessage, bool IsError, CWnd* MainWnd),ssh_session session, CString & ShellEcho, char * cmd, CWnd* MainWnd)
{
ssh_channel channel;
int rc;
channel = ssh_channel_new(session);
if (channel == NULL) return SSH_ERROR;
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK)
{
ssh_channel_free(channel);
return rc;
}
rc = ssh_channel_request_exec(channel, cmd);
if (rc != SSH_OK)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
}
char buffer[256];
unsigned int nbytes;
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0)
{
if (fwrite(buffer, 1, nbytes, stdout) != nbytes)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
return SSH_OK;
}
Makefile位于根目录:
all: mpi_cuda.o pattern2d.o
mpicc mpi_cuda.o pattern2d.o -o mpi_cuda -lrt -lpthread -L/opt/cuda/lib64 -lcudart -lm
mpi_cuda.o: mpi_cuda.c
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c $< -o $@
pattern2d.o: pattern2d.cu
nvcc -g -c $< -o $@
我发送命令"make"并接收回波:
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c mpi_cuda.c -o mpi_cuda.oda
但是什么也没发生(不执行编译(。
如果我真的用油灰做:一切都可以。回声:
make
mpicc -g -std=c99 -D_GNU_SOURCE -I/opt/cuda/include -c mpi_cuda.c -o mpi_cuda.o
mpi_cuda.c: В функции ‘main’:
mpi_cuda.c:148: предупреждение: недостаточно аргументов для указанного формата
nvcc -g -c pattern2d.cu -o pattern2d.o
mpicc mpi_cuda.o pattern2d.o -o mpi_cuda -lrt -lpthread -L/opt/cuda/lib64 -lcudart -lm
我该如何解决此问题?
不熟悉libssh,但错误可能是,因为环境设置不同,所以显式运行make-throughshell可能会有所帮助。
尝试将命令(make
?(更改为
bash -c make
如果不起作用,请尝试
bash -c "export > env.txt ; make > make_out.txt 2> make_err.txt"
然后检查这些文件是否出现,以及它们包含的内容,这应该会给出很好的提示。
如果您有一个工作案例和一个非工作案例,那么从这两个案例中获取这些文件,并将它们进行比较(例如,与diff -u
(。
如果您不使用bash,请将bash
更改为您使用的任何shell(在这种情况下,请检查-c
是否是给出命令字符串的正确开关,以及export
是否是显示环境的正确命令(。
基于以下注释:env.txt中的差异可能是,因为一些环境变量只为交互式shell设置。例如,在我的Ubuntu框中,.bashrc的开头有这样的行:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
现在,如果在该行之后的.bashrc中设置了任何所需的环境变量,并且您的ssh连接是非交互式的(没有伪tty(,则不会设置这些变量。
如果是这种情况,请在进行上述测试之前,将这些env变量集移动到~/.profile
或~/.bashrc
中。还要执行man bash
,并阅读有关初始化文件的内容(如~/.bashrc
(。
另一个解决方案是使ssh会话具有交互性,我相信这一点在本页中有关于libssh的文档:http://api.libssh.org/master/libssh_tutor_shell.html。
我建议打开一个非交互式shell并在那里执行。参见
http://api.libssh.org/master/libssh_tutor_shell.html
- 运行同一解决方案的另一个项目的项目
- 如何在使用Makefile构建后在cmd中运行该程序?
- 在Windows上运行Linux Makefile(.so文件)
- 有没有办法为 c++ 制作一个 makefile,每次使用 make 命令时都会运行该程序?
- Eclipse 中的 Makefile 项目可以运行,但不能调试,为什么?
- makefile运行它编制的代码
- 在Linux Makefile上运行MPI程序
- 如何使用 Makefile 编译后运行程序
- 为什么我在某些计算机上运行Makefile时会出现“未定义引用”错误,而在其他计算机上却没有
- 在Linux中执行C++makefile时出现问题(在mac上运行良好)
- C/ c++ -可编程运行Makefile
- 如何在终端上运行Netbeans makefile
- SDL应用程序的Makefile仅在项目提前构建时运行
- 如何在不使用cygwin的情况下在Windows (Vista)中运行c++文件的makefile
- 如何强制重新运行cmake,或通过CMakeLists.txt添加功能到makefile
- 为c++程序创建makefile,以便与c++一起运行
- 运行makefile——add-stdcall-alias时的JNI问题
- Makefile问题:错误127,255,在Makefile中运行程序
- 当环境变量发生变化时,让基于makefile的cmake项目自动运行make-rebuild_cache
- 如何使用libssh运行makefile