scons 找不到#include 文件

scons can't find #include files

我正在学习有关设置 gdnative 的 this 教程。

我已经通过visual studio、python 3.2和scons 4.1.0

安装了c++工具

我一直在尝试让 scons 构建 this gdnative 示例。我遇到的问题似乎是 scons 无法找到 #include 文件。我试过使用子目录的相对文件路径 godot-cpp/、同级目录的相对路径 ../godot-cpp/,并使用同级目录的完整路径 E:/Projects/Godot Projects/Units/godot-cpp/,但我得到的是相同的每次都出错。我提供了一个屏幕截图来显示文件结构。我是来自 X64 Native Tools Command Prompt for VS 2019

的 运行 scons

编辑 - 现在也尝试过 运行 作为管理员,同样的错误

左上角:我正在尝试构建的项目以及我需要包含在同级目录中的 cpp 文件。

右上角:项目文件夹的内容。 godot-cpp/ 子目录是左上角同名文件夹的副本。

左下:godot-cpp/

的内容

右下角:godot-cpp/godot-headers 的内容。突出显示的文件是它似乎无法找到的文件。

子目录的相对路径:

E:\Projects\Godot Projects\Units\gdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrc\gdexample.obj /c src\gdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. /Igodot-cpp\godot_headers /Igodot-cpp\include /Igodot-cpp\include\core /Igodot-cpp\include\gen /Isrc
gdexample.cpp
godot-cpp\include\core\Godot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [src\gdexample.obj] Error 2
scons: building terminated because of errors.

兄弟目录的相对路径:

E:\Projects\Godot Projects\Units\gdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrc\gdexample.obj /c src\gdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. "/IE:\Projects\Godot Projects\Units\godot-cpp\godot_headers" "/IE:\Projects\Godot Projects\Units\godot-cpp\include" "/IE:\Projects\Godot Projects\Units\godot-cpp\include\core" "/IE:\Projects\Godot Projects\Units\godot-cpp\include\gen" /Isrc
gdexample.cpp
E:\Projects\Godot Projects\Units\godot-cpp\include\core\Godot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [src\gdexample.obj] Error 2
scons: building terminated because of errors.

兄弟目录的完整路径:

E:\Projects\Godot Projects\Units\gdnative_cpp_example>scons platform=windows
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /Fosrc\gdexample.obj /c src\gdexample.cpp /TP /nologo -DWIN32 -D_WIN32 -D_WINDOWS -W3 -GR -D_CRT_SECURE_NO_WARNINGS -EHsc -D_DEBUG -MDd /I. "/IE:\Projects\Godot Projects\Units\godot-cpp\godot_headers" "/IE:\Projects\Godot Projects\Units\godot-cpp\include" "/IE:\Projects\Godot Projects\Units\godot-cpp\include\core" "/IE:\Projects\Godot Projects\Units\godot-cpp\include\gen" /Isrc
gdexample.cpp
E:\Projects\Godot Projects\Units\godot-cpp\include\core\Godot.hpp(7): fatal error C1083: Cannot open include file: 'gdnative_api_struct.gen.h': No such file or directory
scons: *** [src\gdexample.obj] Error 2
scons: building terminated because of errors.

在从 Godot.hpp line 7gdnative_api_struct.gen.h 的 include 语句之后卡住了。看起来它可以很好地解析路径,但由于某种原因无法打开它们。

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 headers 目录(包含 gdnative_api_struct.gen.h 的目录)引用为 godot_headers,但在您的文件系统中,此文件夹称为 godot-headers- 而不是 _)。因此 scons 无法找到该文件。将文件系统中的目录名称更改为 godot_headers 解决了我的问题。