首页 > 解决方案 > 如何修复“没有这样的文件或目录”库错误?我正在使用 Mingw-w64 编译器和 Netbeans IDE

问题描述

我想创建一个基于文本的界面 (TUI) 软件。我在 GitHub 上找到了 FTXUI 库,想用它,所以我把它下载到我的电脑上。项目存储库结构为:

FTXUI-master
├───.github
├───doc
├───examples
│   ├───component
│   ├───dom
│   ├───html
│   └───util
├───include
│   └───ftxui
│       ├───component
│       ├───dom
│       ├───screen
│       └───util
├───other
└───src
    └───ftxui
        ├───component
        ├───dom
        └───screen

我正在使用 Netbeans 8.2 RC 和 Mingw-w64 编译器,首先我尝试在 Netbeans 中添加包含和源,将 FTXUI 中的“include”和“src”添加到 Netbeans 中的包含和源文件路径中,如下所示:

CppApplication
│
│
├───HeaderFiles
│   └include
│    └───ftxui
│        ├───component
│        ├───dom
│        ├───screen
│        └───util
│
├───SourceFiles
│    └──main.cpp
│    └src
│     └───ftxui
│         ├───component
│         ├───dom
│         ├───screen
│         └───util
├───TestFiles
└───ImportantFiles

main.cpp文件内容为:

#include <cstdlib>

#include "ftxui/dom/elements.hpp"
#include "ftxui/screen/screen.hpp"

#include <iostream>

using namespace std;


int main(int argc, char** argv) {

  using namespace ftxui;

  // Define the document
  Element document =
    hbox({
      text(L"left")   | border,
      text(L"middle") | border | flex,
      text(L"right")  | border,
    });
 
  auto screen = Screen::Create(
    Dimension::Full(),       // Width
    Dimension::Fit(document) // Height
  );
  Render(screen, document);
  std::cout << screen.ToString() << std::endl; 

    return 0;
}

我得到的输出是:

cd 'C:\Users\CurrentUser\Documents\NetBeansProjects\CppApplication_2'
C:\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/CurrentUser/Documents/NetBeansProjects/CppApplication_2'
"/C/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_2.exe
make.exe[2]: Entering directory `/c/Users/CurrentUser/Documents/NetBeansProjects/CppApplication_2'
mkdir -p build/Debug/MinGW-Windows/_ext/3a58e87f
rm -f "build/Debug/MinGW-Windows/_ext/3a58e87f/checkbox.o.d"
g++    -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/_ext/3a58e87f/checkbox.o.d" -o build/Debug/MinGW-Windows/_ext/3a58e87f/checkbox.o ../../../Desktop/FTXUI-master/FTXUI-master/src/ftxui/component/checkbox.cpp
../../../Desktop/FTXUI-master/FTXUI-master/src/ftxui/component/checkbox.cpp:5:10: fatal error: ftxui/component/checkbox.hpp: No such file or directory
 #include "ftxui/component/checkbox.hpp"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make.exe[2]: *** [build/Debug/MinGW-Windows/_ext/3a58e87f/checkbox.o] Error 1
make.exe[2]: Leaving directory `/c/Users/CurrentUser/Documents/NetBeansProjects/CppApplication_2'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/CurrentUser/Documents/NetBeansProjects/CppApplication_2'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 2s)

在此先感谢您的帮助。

标签: c++netbeansmingw

解决方案


您遇到此错误是因为您的 g++ 命令行没有选项可以将任何目录添加到标头搜索路径。所以预处理器只会在当前编译文件的目录和一些预配置的文件夹中寻找你的头文件(引号之间)。要将导向器添加到搜索路径,应使用 -Idir 之类的选项(这是最常用的)。
使用 Netbeans,您可以在以下位置添加一个目录:
Option->C/C++->Code Assistance->C Compiler for gcc。
选项->C/C++->代码辅助->g++ 的 C++ 编译器。


推荐阅读