我正在使用 makefile 进行一些练习,并注意到我尝试编译的 .cpp 文件在尝试执行相应的 .out 文件时出现权限被拒绝错误。我还注意到使用 -c
指令似乎是问题所在。这是因为当我这样做时:
singleton_template_main.o: singleton_template_main.cpp singleton.h
g++ -c singleton_template_main.cpp -o singleton_template_main.out
我收到错误,但是当我这样做时:
singleton_template_main.o: singleton_template_main.cpp singleton.h
g++ singleton_template_main.cpp -o singleton_template_main.out
我没有收到任何错误。可能是什么问题?
我使用的是 macOS Sierra。
最佳答案
-c
标志编译代码(禁止链接),生成中间目标文件 - 这是不可执行的。还值得注意的是,在这种情况下,将输出文件命名为 .out 可能并不可取,目标文件的约定是扩展名,例如 .o 和 >.obj 等。
删除 -c
标志会使编译器根据需要编译和链接代码,从而生成可执行文件 - 从而按预期运行。
关于c++ - .out 将 -c 指令与 g++ 一起使用时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41716785/