scons找不到#include文件
我正在关注有关设置 gdnative 的本教程。
我已经通过 Visual Studio、python 3.2 和 scons 4.1.0 安装了 C++ 工具
我一直试图让 scons 来构建这个gdnative 示例。我遇到的问题似乎是 scons 无法找到 #include 文件。我曾尝试使用子目录的相对文件路径godot-cpp/、同级目录的相对路径以及同级目录../godot-cpp/的完整路径,E:/Projects/Godot Projects/Units/godot-cpp/但我每次都遇到相同的错误。我提供了一个屏幕截图来显示文件结构。我正在运行 sconsX64 Native Tools Command Prompt for VS 2019
编辑 - 现在也尝试以管理员身份运行,同样的错误
左上角:我正在尝试构建的项目以及我需要包含在同级目录中的 cpp 文件。
右上角:项目文件夹的内容。该godot-cpp/子目录是从左上方的同名文件夹的副本。
左下:内容 godot-cpp/
右下: 的内容godot-cpp/godot-headers。突出显示的文件是它似乎找不到的文件。
子目录的相对路径:
E:ProjectsGodot ProjectsUnitsgdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrcgdexample.obj /c srcgdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. /Igodot-cppgodot_headers /Igodot-cppinclude /Igodot-cppincludecore /Igodot-cppincludegen /Isrc
gdexample.cpp
godot-cppincludecoreGodot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [srcgdexample.obj] Error 2
scons: building terminated because of errors.
兄弟目录的相对路径:
E:ProjectsGodot ProjectsUnitsgdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrcgdexample.obj /c srcgdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. "/IE:ProjectsGodot ProjectsUnitsgodot-cppgodot_headers" "/IE:ProjectsGodot ProjectsUnitsgodot-cppinclude" "/IE:ProjectsGodot ProjectsUnitsgodot-cppincludecore" "/IE:ProjectsGodot ProjectsUnitsgodot-cppincludegen" /Isrc
gdexample.cpp
E:ProjectsGodot ProjectsUnitsgodot-cppincludecoreGodot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [srcgdexample.obj] Error 2
scons: building terminated because of errors.
E:ProjectsGodot ProjectsUnitsgdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrcgdexample.obj /c srcgdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. "/IE:ProjectsGodot ProjectsUnitsgodot-cppgodot_headers" "/IE:ProjectsGodot ProjectsUnitsgodot-cppinclude" "/IE:ProjectsGodot ProjectsUnitsgodot-cppincludecore" "/IE:ProjectsGodot ProjectsUnitsgodot-cppincludegen" /Isrc
gdexample.cpp
E:ProjectsGodot ProjectsUnitsgodot-cppincludecoreGodot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [srcgdexample.obj] Error 2
scons: building terminated because of errors.
兄弟目录的完整路径:
在从Godot.hpp line 7to的 include 语句之后,它被卡住了gdnative_api_struct.gen.h。看起来它可以很好地解析路径,但由于某种原因无法打开它们。
SConstruct 文件 - 与我正在尝试构建的项目一起提供。唯一的修改是将路径更改为godot-cpp/和godot-cpp/headers/。
#!python
import os, subprocess
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/'))
opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept))
# Local dependency paths, adapt them to your setup
# These next two lines are where I changed the paths <-----------------
godot_headers_path = "../godot-cpp/godot_headers/"
cpp_bindings_path = "../godot-cpp/"
cpp_library = "libgodot-cpp"
# only support 64 at this time..
bits = 64
# Updates the environment with the option variables.
opts.Update(env)
# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'
if env['p'] != '':
env['platform'] = env['p']
if env['platform'] == '':
print("No valid target platform selected.")
quit();
# Check our platform specifics
# I'm using windows so I cut the other options for readability
if env['platform'] == "windows":
env['target_path'] += 'win64/'
cpp_library += '.windows'
# This makes sure to keep the session environment variables on windows,
# that way you can run scons in a vs 2017 prompt and it will find all the required tools
env.Append(ENV = os.environ)
env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-W3', '-GR', '-D_CRT_SECURE_NO_WARNINGS'])
if env['target'] in ('debug', 'd'):
env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '-MDd'])
else:
env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD'])
if env['target'] in ('debug', 'd'):
cpp_library += '.debug'
else:
cpp_library += '.release'
cpp_library += '.' + str(bits)
# make sure our binding library is properly includes
env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
env.Append(LIBS=[cpp_library])
# tweak this if you want to use different folders, or more folders, to store your source code in.
env.Append(CPPPATH=['src/'])
sources = Glob('src/*.cpp')
library = env.SharedLibrary(target=env['target_path'] + env['target_name'], source=sources)
Default(library)
# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))
回答
我今天遇到了完全相同的问题。在您在 SConstruct 文件中更改的那一行中,您将 godot 头目录(包含 的目录)引用gdnative_api_struct.gen.h为godot_headers,但在您的文件系统中,该文件夹被称为godot-headers(-不是_)。因此 scons 无法找到该文件。更改文件系统中的目录名称以godot_headers解决我的问题。