質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Lua

Luaは、汎用のスクリプト言語の一つで、 移植性が高く、高速な実行速度などの特徴を持ち 手続き型・オブジェクト指向言語としても利用可能で 関数型言語、データ駆動型の要素も併せ持っている言語です。

Q&A

解決済

1回答

2017閲覧

std::experimental::filesystem::(中略)::directory_entryにexists等がないと言われる

idonotknow

総合スコア74

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Lua

Luaは、汎用のスクリプト言語の一つで、 移植性が高く、高速な実行速度などの特徴を持ち 手続き型・オブジェクト指向言語としても利用可能で 関数型言語、データ駆動型の要素も併せ持っている言語です。

0グッド

0クリップ

投稿2018/04/07 04:47

前提・実現したいこと

https://github.com/ElonaFoobar/ElonaFoobar
上記リポジトリをコンパイルしようとしました。

// ライブラリ等の準備 brew install make ???? /usr/local/Cellar/make/4.2.1_1: 15 files, 956KB brew install lua ???? /usr/local/Cellar/lua/5.3.4_3: 147 files, 753KB brew install gcc ???? /usr/local/Cellar/gcc/7.3.0_1: 1,487 files, 285.9MB, built in 65 minutes 39 seconds

また、SDL関連を配布サイトからダウンロードし、readmeに従いファイルを移動させました。

$ pwd /Library/Frameworks $ ls AEProfiling.framework SDL2.framework AERegistration.framework SDL2_image.framework AudioMixEngine.framework SDL2_mixer.framework NyxAudioAnalysis.framework SDL2_ttf.framework PluginManager.framework iTunesLibrary.framework

ElonaFooBarディレクトリでmakeを実行したところ/usr/local/bin/g++-HEADがないと言われたため、CXX := /usr/local/bin/g++-7に書き換えました。
その後makeを実行したところ、以下のエラーメッセージが出てコンパイルに失敗します。

発生している問題・エラーメッセージ

$ make /usr/local/Cellar/gcc/7.3.0_1/bin/g++-7 -Werror -Wall -Wextra -g -O0 -MMD -DDEBUG -std=c++17 -I/usr/local/include -I./thirdparty -I/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7 -c ability.cpp -o bin/./ability.o In file included from cat.hpp:5:0, from ability.hpp:7, from ability.cpp:1: filesystem.hpp: In instantiation of 'elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)> [with auto:1 = std::experimental::filesystem::v1::__cxx11::directory_iterator]': /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/type_traits:2428:26: required by substitution of 'template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)>&; _Args = {std::experimental::filesystem::v1::__cxx11::directory_iterator}]' /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/type_traits:2439:55: required from 'struct std::__result_of_impl<false, false, elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)>&, std::experimental::filesystem::v1::__cxx11::directory_iterator>' /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/type_traits:2444:12: required from 'struct std::__invoke_result<elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)>&, std::experimental::filesystem::v1::__cxx11::directory_iterator>' /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/type_traits:2457:12: required from 'class std::result_of<elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)>&(std::experimental::filesystem::v1::__cxx11::directory_iterator)>' /usr/local/Cellar/gcc/7.3.0_1/include/c++/7.3.0/bits/std_function.h:464:9: required by substitution of 'template<class _Functor, class, class> std::function<bool(std::experimental::filesystem::v1::__cxx11::directory_iterator)>::function(_Functor) [with _Functor = elona::filesystem::dir_entries::begin() const::<lambda(const auto:1&)>; <template-parameter-1-2> = void; <template-parameter-1-3> = <missing>]' filesystem.hpp:134:18: required from here filesystem.hpp:114:31: error: 'const class std::experimental::filesystem::v1::__cxx11::directory_entry' has no member named 'exists' if (!itr->exists()) ~~~~~^~~~~~ filesystem.hpp:119:35: error: 'const class std::experimental::filesystem::v1::__cxx11::directory_entry' has no member named 'is_directory' if (!itr->is_directory()) ~~~~~^~~~~~~~~~~~ filesystem.hpp:125:35: error: 'const class std::experimental::filesystem::v1::__cxx11::directory_entry' has no member named 'is_regular_file' if (!itr->is_regular_file()) ~~~~~^~~~~~~~~~~~~~~ make: *** [bin/./ability.o] Error 1

該当のソースコード

makefileはhttps://github.com/ElonaFoobar/ElonaFoobar/blob/master/Makefileを書き換え、最終的に以下のようになっています。

CXX := /usr/local/Cellar/gcc/7.3.0_1/bin/g++-7 CXX_FLAGS := -Werror -Wall -Wextra -g -O0 -MMD -DDEBUG -std=c++17 -I/usr/local/include -I./thirdparty -I/usr/local/Cellar/gcc/7.3.0_1/lib/gcc/7 $(EX_CXX_FLAGS) LN_FLAGS := -lstdc++fs -L/usr/local/lib -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer -llua BIN_DIR := bin SRC_DIR := . SOURCES := $(wildcard $(SRC_DIR)/*.cpp) OBJECTS := $(foreach i, $(SOURCES), $(BIN_DIR)/$(basename $(i)).o) RUNTIME_DIR := ./runtime PROGRAM := $(RUNTIME_DIR)/elonafoobar FORMAT := clang-format FIND := find XARGS := xargs MKDIR := mkdir .PHONY: FORCE clean cleandep all: build build: $(RUNTIME_DIR) $(BIN_DIR) $(PROGRAM) $(RUNTIME_DIR): $(MKDIR) $(RUNTIME_DIR) $(BIN_DIR): $(MKDIR) $(BIN_DIR) $(PROGRAM): $(OBJECTS) snail/snail.a $(CXX) $(CXX_FLAGS) $^ -o $@ $(LN_FLAGS) snail/snail.a: FORCE cd snail; make $(BIN_DIR)/%.o: $(SRC_DIR)/%.cpp $(CXX) $(CXX_FLAGS) -c $< -o $@ clean: -@$(RM) -f $(PROGRAM) $(MAKE) cleandep -@$(RM) -f $(BIN_DIR)/*.o format: FORCE $(FIND) $(SRC_DIR) ( -name "*.cpp" -or -name "*.hpp" ) -print0 | $(XARGS) -0 $(FORMAT) -i checksyntax: $(MAKE) EX_CXX_FLAGS=-fsyntax-only cleandep: -@$(RM) -f $(BIN_DIR)/*.d rebuild: clean build -include $(BIN_DIR)/*.d

エラーの発生したファイルはこちらです。

cpp

1// https://github.com/ElonaFoobar/ElonaFoobar/blob/master/filesystem.hpp 2#pragma once 3 4#if __has_include(<filesystem>) 5#include <filesystem> 6namespace fs = std::filesystem; 7#else 8#include <experimental/filesystem> 9namespace fs = std::experimental::filesystem; 10#endif 11#include <functional> 12#include <regex> 13#include "range.hpp" 14 15 16 17namespace elona::filesystem 18{ 19 20 21struct dir_entries 22{ 23 enum class type 24 { 25 dir, 26 file, 27 all, 28 }; 29 30 31 dir_entries( 32 const fs::path& base_dir, 33 type entry_type, 34 const std::regex& pattern = std::regex{u8".*"}) 35 : base_dir(base_dir) 36 , entry_type(entry_type) 37 , pattern(pattern) 38 { 39 } 40 41 42 struct iterator 43 { 44 using value_type = fs::directory_iterator::value_type; 45 using difference_type = fs::directory_iterator::difference_type; 46 using pointer = fs::directory_iterator::pointer; 47 using reference = fs::directory_iterator::reference; 48 using iterator_category = fs::directory_iterator::iterator_category; 49 50 51 // begin 52 iterator( 53 const fs::directory_iterator& itr, 54 std::function<bool(const fs::directory_iterator)> predicate) 55 : itr(itr) 56 , predicate(predicate) 57 { 58 while (predicate(this->itr)) 59 { 60 ++this->itr; 61 } 62 } 63 64 65 // end 66 iterator() 67 { 68 } 69 70 71 void operator++() 72 { 73 do 74 { 75 ++itr; 76 } while (predicate(itr)); 77 } 78 79 80 reference operator*() const 81 { 82 return *itr; 83 } 84 85 86 pointer operator->() const 87 { 88 return itr.operator->(); 89 } 90 91 92 bool operator==(const iterator& other) const 93 { 94 return itr == other.itr; 95 } 96 97 98 bool operator!=(const iterator& other) const 99 { 100 return itr != other.itr; 101 } 102 103 104 private: 105 fs::directory_iterator itr; 106 std::function<bool(const fs::directory_iterator)> predicate; 107 }; 108 109 110 iterator begin() const 111 { 112 return {fs::directory_iterator{base_dir}, [this](const auto& itr) { 113 if (itr == fs::directory_iterator{}) 114 return false; 115 if (!itr->exists()) 116 return true; 117 switch (entry_type) 118 { 119 case type::dir: 120 if (!itr->is_directory()) 121 { 122 return true; 123 } 124 break; 125 case type::file: 126 if (!itr->is_regular_file()) 127 { 128 return true; 129 } 130 break; 131 case type::all: break; 132 } 133 return !std::regex_match( 134 itr->path().filename().generic_u8string(), pattern); 135 }}; 136 } 137 138 139 iterator end() const 140 { 141 return {}; 142 } 143 144 145private: 146 const fs::path base_dir; 147 const type entry_type; 148 const std::regex pattern; 149}; 150 151 152 153} // namespace elona::filesystem

試したこと

エラー文を見るとstdライブラリの中のdirectory_entryのメソッドがないと言われていたので、きっとライブラリを参照し損ねているのだと思い、makeファイルのCXX_FLAGSのオプションにusr/local/Cellar/gcc/7.3.0_1/lib/gcc/7を追加しました。それでもエラーは変わらず発生したので、 CXX := /usr/local/Cellar/gcc/7.3.0_1/bin/g++-7に試しに変更してみましたが、エラーは直りませんでした。

補足情報(FW/ツールのバージョンなど)

  • macOS 10.13.3
  • gcc 7.3.0_1
  • Visual Studio Code 1.19.3

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

調べたところ
<experimental/filesystem>はexistsはないバージョンで
<filesystem>をインクルードする必要があるみたいですね。

そしてGCC7.3は<filesystem>をサポートしていないようです。
どうやらGCC8以降が必要みたいですね

投稿2018/04/08 05:47

asm

総合スコア15147

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

idonotknow

2018/04/08 08:35

> <experimental/filesystem>はexistsはないバージョンで > <filesystem>をインクルードする必要があるみたいですね。 7系と8系で差異があるのに気づきませんでした……ありがとうございます 頑張ってgcc 8系を導入しようと思います
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問