Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何告诉Sublime Text在C++;_C++_Sublimetext - Fatal编程技术网

C++ 如何告诉Sublime Text在C++;

C++ 如何告诉Sublime Text在C++;,c++,sublimetext,C++,Sublimetext,要编译并运行升华文本2中的.cpp文件,我按command+shift+B。但我不知道如何告诉升华文本链接外部.h文件。当我放入#include“genlib.h”并编译时,我收到了这个错误 /Users/ckaj/Desktop/main.cpp:1:10: fatal error: 'genlib.h' file not found #include "genlib.h" ^ 1 error generated. [Finished in 0.2s with exit c

要编译并运行升华文本2中的.cpp文件,我按command+shift+B。但我不知道如何告诉升华文本链接外部.h文件。当我放入#include“genlib.h”并编译时,我收到了这个错误

/Users/ckaj/Desktop/main.cpp:1:10: fatal error: 'genlib.h' file not found
#include "genlib.h"
          ^
1 error generated.
[Finished in 0.2s with exit code 1]
[shell_cmd: g++ "/Users/ckaj/Desktop/main.cpp" -o "/Users/ckaj/Desktop/main"]
[dir: /Users/ckaj/Desktop/]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
所以,我试着把“genlib.h”文件放在同一个目录中,看看它是如何工作的。我得到一个不同的错误,如下所示

In file included from /Users/ckaj/Desktop/main.cpp:1:
 /Users/ckaj/Desktop/genlib.h:225:1: error: expected unqualified-id
 <U+001A>
^
 1 error generated.
[Finished in 0.2s with exit code 1]
[shell_cmd: g++ "/Users/ckaj/Desktop/main.cpp" -o "/Users/ckaj/Desktop/main"]
[dir: /Users/ckaj/Desktop/]
[path: /usr/bin:/bin:/usr/sbin:/sbin]
包含在/Users/ckaj/Desktop/main.cpp:1中的文件中:
/Users/ckaj/Desktop/genlib.h:225:1:错误:应为非限定id
^
生成1个错误。
[在0.2秒内完成,退出代码为1]
[shell_cmd:g++“/Users/ckaj/Desktop/main.cpp“-o”/Users/ckaj/Desktop/main”]
[dir:/Users/ckaj/Desktop/]
[路径:/usr/bin:/bin:/usr/sbin:/sbin]

我已经找了几个小时的答案,但都没有找到。我要感谢任何人,试图帮助我修复崇高文本2的工作

谢谢大家的帮助。我终于看完了构建文档。如果您了解如何在命令行上使用g++进行编译,那么这看起来非常简单。答案是这样的

{
    "cmd": ["g++ -Wall ${file} -o ./bin/${file_base_name} -I${file_path}/lib && ./bin/${file_base_name}"],
    "selector": "source.c++",
    "working_dir": "${file_path}",
    "shell": true,


    "variants": [
        {
            "name": "Run",
            "cmd": ["g++ -Wall ${file} -o ./bin/${file_base_name} -I${file_path}/lib && open ./bin/${file_base_name}"],
            "working_dir": "${file_path}",
            "shell": true

        }
     ]

}

按照@Mick的想法,这对我来说很有用(sublime text 3,ubuntu 15.10):


您需要更改生成系统以具有其他包含路径,即与您的文件一起使用的路径。您介意给我一个如何执行此操作的说明吗?我真的是一个新的崇高的文本。非常感谢,还有一个。除此之外,它只是为GCC添加了正确的选项,这与Sublime无关。谢谢Chris。我还没有完全理解这里的构建系统。我将试着阅读文档,看看它是如何工作的。@Mick现在你已经找到了解决方案,你的编辑应该成为你自己的答案,你会接受的。
{
    "cmd": ["g++ -std=c++0x ${file_path}/*.cpp -o tmp && ./tmp"],  
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "shell": true
}