c++ - .out 将 -c 指令与 g++ 一起使用时权限被拒绝

标签 c++ macos makefile compilation g++

我正在使用 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/

相关文章:

makefile - Makefile 中的复杂模式规则

c - 如何为visual studio构建工具cl.exe编写makefile(nmake)

c++ - 操纵 C 风格的字符串?

c++ - ( __ printf __ ) 在 DLL (programfiles(x86)\codeblocks\mingw\bin\as.exe) 中找不到

c++ - 用堆栈中缀的后缀。

c++ - 检查类型是否被声明为元类型系统(对于 SFINAE)

postgresql - brew uninstall OSX 后完全删除 postgres

ios - arc4random_uniform() 的操作系统要求

ios - 核心数据设计 : better 1 model with 2 stores or 2 models and 2 stores?

c - Make 不编译好的文件