hae*_*ael 3 command-line compiling gcc
我用 C 编写了一个程序,我试图用参数在命令行上编译它,但是当我写一个整数时,例如:
gcc findtopk.c -o findtopk 500 5 test1.txt test2.txt test3.txt test4.txt test5.txt outfile.txt
Run Code Online (Sandbox Code Playgroud)
它说:
gcc: error: 500: No such file or directory
gcc: error: 5: No such file or directory
Run Code Online (Sandbox Code Playgroud)
ste*_*ver 11
您似乎试图在编译时将运行时参数传递给您的程序 - 据我所知,这是行不通的。接受的唯一非选项参数gcc是要编译的文件的名称。
很难给出精确的说明,因为你没有分享你的程序的源代码(或解释它如何处理参数),但你想要的可能是这样的:
gcc findtopk.c -o findtopk
Run Code Online (Sandbox Code Playgroud)
编译和链接您的程序;然后
./findtopk 500 5 test1.txt test2.txt test3.txt test4.txt test5.txt outfile.txt
Run Code Online (Sandbox Code Playgroud)
使用参数 list 运行它test1.txt test2.txt test3.txt test4.txt test5.txt outfile.txt。
C 中参数解析的细节在这里是题外话,但有很多在线资源,例如