【问题标题】:Error with array.h headersarray.h 标头错误
【发布时间】:2018-11-26 18:22:15
【问题描述】:

我使用 CLion,我有这个简单的代码:

#include <array>

int main() {

    std::array<std::uint64_t, 3> arr;
    return 0;
}

在我的CMakeLists.txt 中,我尝试了从 c++11/gnu++11 到 c++17/gnu++17 的所有编译器标志,但是在尝试构建上面的代码时,我不断收到此错误

/pathToCLion/clion-2018.1.2/bin/cmake/bin/cmake --build 

/pathToCLionProject/my_project/cmake-build-default --target my_project -- -j 2
/pathToCLion/clion-2018.1.2/bin/cmake/bin/cmake -H/pathToCLionProject/my_project -B/pathToCLionProject/my_project/cmake-build-default --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/gmake -f CMakeFiles/Makefile2 my_project
gmake[1]: Entering directory '/pathToCLionProject/my_project/cmake-build-default'
/pathToCLion/clion-2018.1.2/bin/cmake/bin/cmake -H/pathToCLionProject/my_project -B/pathToCLionProject/my_project/cmake-build-default --check-build-system CMakeFiles/Makefile.cmake 0
/pathToCLion/clion-2018.1.2/bin/cmake/bin/cmake -E cmake_progress_start /pathToCLionProject/my_project/cmake-build-default/CMakeFiles 2
/usr/bin/gmake -f CMakeFiles/Makefile2 CMakeFiles/my_project.dir/all
gmake[2]: Entering directory '/pathToCLionProject/my_project/cmake-build-default'
/usr/bin/gmake -f CMakeFiles/my_project.dir/build.make CMakeFiles/my_project.dir/depend
gmake[3]: Entering directory '/pathToCLionProject/my_project/cmake-build-default'
cd /pathToCLionProject/my_project/cmake-build-default && /pathToCLion/clion-2018.1.2/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /pathToCLionProject/my_project /pathToCLionProject/my_project /pathToCLionProject/my_project/cmake-build-default /pathToCLionProject/my_project/cmake-build-default /pathToCLionProject/my_project/cmake-build-default/CMakeFiles/my_project.dir/DependInfo.cmake --color=
Scanning dependencies of target my_project
gmake[3]: Leaving directory '/pathToCLionProject/my_project/cmake-build-default'
/usr/bin/gmake -f CMakeFiles/my_project.dir/build.make CMakeFiles/my_project.dir/build
gmake[3]: Entering directory '/pathToCLionProject/my_project/cmake-build-default'
[ 50%] Building CXX object CMakeFiles/my_project.dir/dev/hmmenc_client/test.cpp.o
/usr/bin/c++   -I/pathToCLionProject/my_project -I/pathToCLionProject/my_project/dev/hmmenc_client -I/usr/local/include/pqxx -I/usr/pgsql-10/include  -pthread -std=gnu++11 -o CMakeFiles/my_project.dir/dev/hmmenc_client/test.cpp.o -c /pathToCLionProject/my_project/dev/hmmenc_client/test.cpp
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp: In function ‘int main()’:
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:9:10: error: ‘array’ is not a member of ‘std’
     std::array<std::uint64_t, 3> arr;
          ^~~~~
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:9:10: note: ‘std::array’ is defined in header ‘<array>’; did you forget to ‘#include <array>’?
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:6:1:
+#include <array>

/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:9:10:
     std::array<std::uint64_t, 3> arr;
          ^~~~~
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:9:29: error: expected primary-expression before ‘,’ token
     std::array<std::uint64_t, 3> arr;
                             ^
/pathToCLionProject/my_project/dev/hmmenc_client/test.cpp:9:34: error: ‘arr’ was not declared in this scope
     std::array<std::uint64_t, 3> arr;
                                  ^~~
gmake[3]: *** [CMakeFiles/my_project.dir/build.make:66: CMakeFiles/my_project.dir/dev/hmmenc_client/test.cpp.o] Error 1
gmake[3]: Leaving directory '/pathToCLionProject/my_project/cmake-build-default'
gmake[2]: *** [CMakeFiles/Makefile2:71: CMakeFiles/my_project.dir/all] Error 2
gmake[2]: Leaving directory '/pathToCLionProject/my_project/cmake-build-default'
gmake[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/my_project.dir/rule] Error 2
gmake[1]: Leaving directory '/pathToCLionProject/my_project/cmake-build-default'
gmake: *** [Makefile:121: my_project] Error 2

这是我的 g++ 版本:gcc 版本 8.1.1 20180502 (Red Hat 8.1.1-1) (GCC)。什么可能导致此错误?

【问题讨论】:

  • 我很好奇为什么这个问题被否决了。 (我只是赞成将其恢复为 0。)OP 给了我们一个最小的例子,错误信息非常复杂,解决方案(如果答案是正确的)将需要我们中的许多人很长时间才能弄清楚我们自己的。投诉什么?

标签: c++ c++11 cmake g++ clion


【解决方案1】:

如果您在包含路径(/pathToCLionProject/my_project/pathToCLionProject/my_project/dev/hmmenc_client/usr/local/include/pqxx/usr/pgsql-10/include)上列出的任何目录中有一个名为 array 的空文件,则会发生此错误。

【讨论】:

  • 感谢您的提示。我在导致问题的/usr/local/include/pqxx 路径中发现了一个名为array 的非空文件。最后,这是我的错,我不应该在使用包的路径中包含/pqxx
猜你喜欢
  • 2021-09-11
  • 2016-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-14
  • 1970-01-01
  • 2015-05-02
  • 1970-01-01
相关资源
最近更新 更多