从Shell脚本调用C程序 [英] Call C program from shell script

查看:907
本文介绍了从Shell脚本调用C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是Unix的新手.
我想从shell脚本调用我的C程序.
在C我创建一个简单的应用程序,它接受2个文件作为参数并打印.
我创建了一个具有以下内容的shell脚本,

Hi,
I am a new to Unix.
I want to call my C program from shell script.
For that i created one simple application in C, which accepts 2 files as argument and print it.
I created one shell script having following contents,

cc -o Test Test.cpp
Test ABC.txt XYZ.txt


这对我来说可以.这是正确的方法吗?如果还有其他方法可用,请告诉我.

现在,我想用一个文件作为参数创建一个shell脚本,我需要将它以另外一个文件作为参数传递给我的.cpp文件.
但我的.cpp文件中有一些用户定义的头文件和头文件也有其他的头文件.
在编译我的.cpp文件时,我收到该子头文件的错误.要删除它,我使用了cc -I选项,但是对于所有头文件,我需要在我的shell脚本中提到一个不好的程序的路径.
有些文件具有权限被拒绝",我如何包含它进行编译.
有什么办法可以编译吗?
有人可以告诉我该怎么做吗?

在此先谢谢您.


It works fine for me. Is it the correct way? If any other way is also available please let me know.

Now i want to create one shell script with one file as parameter and i need to pass it to my .cpp file with one more file as parameter.
But my .cpp file had some user defined header files, and that header files also has other header files.
While compiling my .cpp file i am receiving error for that sub header files. To remove that i used cc -I option, but for all header files i need to mention the path in my shell script which is not a good program.
Some files had "Permission Denied", how can I include it for compilation.
Is there any way to do the compilation?
Can anybody tell me about how can I do this?

Thanks in advance.

推荐答案

通常,它将被脚本化" 分别 :):
-建设阶段(开发)
(用于编译和链接,使用生成文件的脚本...)
-通话阶段(用户)
(脚本以其参数启动已构建的(到第一阶段)可执行文件...)

例如:):
脚本1,用于开发:
Usually it will be "scripted" separately :) :
- Build stage (development)
(scripts to compile and link, to use make-files...)
- Call stage (users)
(scripts to start the built (by first stage) executables with their parameters...)

For example :) :
Script 1, used at develpment:
cc -o Test Test.cpp


脚本2,供用户使用


Script 2, used by users

Test ABC.txt XYZ.txt







Poonamol写道:
Poonamol wrote:

如果我创建了一个make文件来创建.lib和.obj文件,那么可以将make文件的引用放进去带有参数的shell脚本?

If I create a make file to create .lib and .obj files, then is it possible to gice the reference of make file into the shell script with parameters?



[



Yes[^] , it would be something like this :) :

make -f test.mak -I /usr/poony/my_includes


请以示例详细说明.

如果我创建了一个make文件来创建.lib和.obj文件,那么是否可以将带有参数的make文件的引用添加到shell脚本中?


:-O
Can you please elaborate on this with example.

If I create a make file to create .lib and .obj files, then is it possible to gice the reference of make file into the shell script with parameters?


:-O




我已经创建了makefile来进行编译和创建.exe文件.
但是在执行makefile时,我收到以下错误

0711-317错误:未定义的符号:.fn_error(......)
0711-345使用-bloadmap或-bnoquiet选项,以获得更多的信息.
make:......错误8

您能否帮助我摆脱它,并为我的代码创建正确的可执行文件.

预先感谢.
Hi,

I had created makefile to compile and create .exe file.
but while executing makefile i am receiving following error

0711-317 Error: undefined symbol: .fn_error(......)
0711-345 use the -bloadmap or -bnoquiet option to obtain more information.
make :...... Error 8

Could you please help me to get out of it and create proper executable of my code.

Thanks in advance.


这篇关于从Shell脚本调用C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆