简体   繁体   English

从工作区外部编译 c 文件

[英]compile c file from outside of workspace

I have a c file that it's located in the folder /my_test as shown below.我有一个 c 文件,它位于文件夹 /my_test 中,如下所示。 I can run the command below successfully if I'm located on the "my_test" directory.如果我位于“my_test”目录中,我可以成功运行以下命令。

~/my_test$ strace -e write -f gcc -I/home/user/my_test/headers -fsyntax-only mymainfile.c  

is it possible to run the same command from a different directory?是否可以从不同的目录运行相同的命令? Let's say I'm in /home/user/new_test instead.假设我在 /home/user/new_test 中。

~/new_test$ strace -e write -f gcc -I/home/user/my_test/headers -fsyntax-only -I/home/user/my_test/mymainfile.c  

I believe the "-I" flag only works for header files only correct?我相信“-I”标志仅适用于 header 文件是否正确? is there an equivalent flag for the c file? c 文件是否有等效标志?

The -I mean adding extras headers path, the same thing for -L but for precompiled objects (libraries). -I的意思是添加额外的标头路径,与-L相同,但用于预编译对象(库)。

So you need to remove -I you did, the command should be like this:所以你需要删除-I you did,命令应该是这样的:

~/new_test$ strace -e write -f gcc -I/home/user/my_test/headers -fsyntax-only /home/user/my_test/mymainfile.c

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM