通过2个.cpp文件制作文件(UNIX) [英] Make file by 2 .cpp files (UNIX)

查看:67
本文介绍了通过2个.cpp文件制作文件(UNIX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在一个文件夹中有2个文件first.cpp和second.cpp.每个文件带有2个整数的命令行参数.我想制作一个名为"Robot"的make文件,以便可以像下面这样直接运行该程序:::

机器人优先123412 1212



机器人第二台4124 214214

请帮我.我到处搜索,但没有找到确切的命令....

Let suppose I have 2 files first.cpp and second.cpp in a folder. Each file takes 2 command line arguments that is integers. I want to make the make file named "Robot" So that I can directly run the program like following:::

Robot first 123412 1212

Or

Robot second 4124 214214

PLease help me. I have searched everywhere but didnot find the exact commands....

推荐答案

如果我正确理解了您的问题,您将无法真正做到这一点.

我猜您目前有两个可以像这样使用的程序:
You cannot really do that... if I understand your question correctly.

I guess you presently have two programs that can be used like that:
first 123412 1212




or

second 4124 214214



并且您只需要一个程序,但要在第一个参数中指定要使用的函数".

如果要这样做,则必须在first.cppsecond.cpp中重命名现有的main,并创建第三个文件,该文件将解析命令行并根据第一个参数调用适当的函数.



and you want a single program but specify in first argument which "function" to use.

If this is want you want to do, then you have to rename existing main in first.cpp and second.cpp and create a third file that would parse the command line and call the appropriate function depending on the first argument.


通常看一下手册是个好主意,因此,让您开始阅读此页面顶部的示例:
Simple-Makefile [
It''s usually a good idea to take a look at the manual, so to get you started take a look at the sample on the top of this page:
Simple-Makefile[^]

Best regards
Espen Harlinn


这篇关于通过2个.cpp文件制作文件(UNIX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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