本文介绍了#include< glad/glad.h&gt ;:没有这样的文件或目录(即使源和标头位于同一目录中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始将用Java(使用lwjgl)编写的游戏引擎转换为C/C ++.我在Fedora 25上使用Qt Creator和CMake(我很确定这不会影响任何东西)来链接所有目录,文件等.GLFW已安装在我的系统上,但我决定使用源代码版本,而不是比随附的版本.我为我的扩展程序加载程序感到高兴,并按照 GLFW上的教程进行了配置网站.我还没有通过"Hello World"测试,因为当我在main.c文件中包含glad.h文件时,我得到一个错误:

I recently started converting a game engine I wrote in Java (using lwjgl) to C/C++. I am using Qt Creator and CMake on Fedora 25 (I'm pretty sure this doesn't affect anything) to link all the directories, files, etc. GLFW is installed on my system, but I decided to use the source version, rather than the included version. I am using glad for my extension loader, and configured it following the tutorial on the GLFW website. I haven't gotten past the "Hello World" test because when I include the glad.h file in my main.c file, I get an error:

<glad/glad.h>: No such file or directory

同样奇怪的是,我在glad.c文件中遇到了同样的错误,该错误是使用Glad自己的生成器创建的.我的main.c文件看起来像这样

What is equally strange is that I get this same error in the glad.c file, the one that was created using glad's own generator. My main.c file looks like this

#include <stdio.h>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main(int argc, char *argv[])
{
    printf("Kick Ass Game Engine");
    return 0;
}

我还尝试使用"glad.h:代替<glad/glad.h>(我发现建议).这确实适用于我的main.c文件,但是即使对glad.c文件进行编辑以反映main.c之后,我对glad.c文件仍然存在相同的问题.

I have also tried using "glad.h: instead of <glad/glad.h> (I found that suggestion here). This did work for my main.c file, but I still have the same issue with the glad.c file, even after I edited it to reflect main.c.

我的项目目录如下:

- KAGE/
  -> CMakeLists.txt
  -> glad.c
  -> glad.h
  -> main.c
  -> khplatform.h
-> KAGE/lib/
   -> glad
   -> glfw-3.2.1

如您所见,我的所有.c及其头文件都位于一个目录中. lib目录是我保持高兴和高兴的地方.我只是将文件从lib/glad目录复制到主项目之一.

As you can see, all of my .c and their header files are in one directory. The lib directory is where I keep glad and glfw. I just copied the files from the lib/glad directory to the main project one.

我的CMake看起来像这样

project(KAGE)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

add_subdirectory(/home/brian/KAGE/lib/glfw-3.2.1)

find_package(OpenGL REQUIRED)

target_link_libraries(KAGE glfw)

我曾尝试搜索,但是人们在尝试调用系统上安装的库时遇到的所有问题.没有安装我的.我有一个单独的目录(lib),其中保存了我使用的所有内容.我发现唯一与我要寻找的解决方案接近的解决方案是用"glad.h"替换<glad/glad.h>的解决方案.就像我之前说的那样,这是行不通的. GLFW网站上的教程不提供任何其他信息或故障排除.

I have tried searching around, but all of the issues people had where when trying to call libraries installed on the system. Mine are not installed. I have a separate directory (lib) where I keep everything I use. The only solution I found that came close to what I was looking for was the one about replacing <glad/glad.h> with "glad.h". As I said earlier, this did not work. The tutorial on GLFW's website does not offer any other information or troubleshooting.

任何帮助或建议,我们将不胜感激.谢谢.

Any help or suggestions is greatly appreciated. Thank you.

推荐答案

CMake默认不包括当前目录.要启用此行为,您需要设置 CMAKE_INCLUDE_CURRENT_DIR 变量:

CMake doesn't include current directory by default. For enable this behavior you need to set CMAKE_INCLUDE_CURRENT_DIR variable:

set(CMAKE_INCLUDE_CURRENT_DIR ON)

在此之后,您的glad.c文件可以使用包含标题的文件

After that for including the header your glad.c file may use

#include "glad.h"

这篇关于#include&lt; glad/glad.h&gt ;:没有这样的文件或目录(即使源和标头位于同一目录中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 21:30