【发布时间】:2019-07-21 20:28:58
【问题描述】:
我正在使用 C++ 开发一个小型迷宫游戏。我的问题:我喜欢 Visual Studio Code for Linux,当我运行我的程序时,我收到以下错误:
main.cpp:2:10:fatal error: Player.h: No such file or directory
包括“Player.h”
我使用以下文件夹结构设置这个项目:
Game
|-------include
|----------GameMap.h
|----------Map.h
|----------MapCell.h
|----------Player.h
|-------src
|----------GameMap.cpp
|----------Map.cpp
|----------MapCell.cpp
|----------Player.cpp
|-------main.cpp
这个项目在我使用的另一台计算机上运行,当我使用代码块时它也运行。但是因为我喜欢继续使用可视化代码,所以我希望能够在使用 Visual Studio 代码时编译和运行我的 C++ 代码。
g++ -o main main.cpp
编辑:
c_cpp_properties.json
{
"configurations":[
{
"name":"Linux",
"includePath":[
"${workspaceFolder}/**",
"/home/roger/Documents/01.Curso_de_CPP/Projecto/Game_02/Headers/include/**"
],
"defines":[
"_DEBUG"
],
"forcedInclude":[
"/home/roger/Documents/01.Curso_de_CPP/Projecto/Game_02/Headers/include/Player.h"
],
"compilerPath":"/usr/bin/gcc",
"cStandard":"c11",
"cppStandard":"c++17",
"intelliSenseMode":"clang-x64"
}
],
"version":4
}
【问题讨论】:
-
你设置了包含路径吗?
-
对不起。我是 C++ 新手,不知道该怎么做。我使用代码块作为编辑器启动了这个项目,它在目录中找到了头文件。我以前没有这个链接器问题。但我不知道如何在可视代码中设置我的项目,以便我的 main.cpp 编译。
-
也许可以读一下:C/C++ for Visual Studio Code
-
undefined reference to ‘Player::Player()‘表示它可以编译,但不能正确链接。Player的目标文件未链接到可执行文件。
标签: compilation header g++