尝试在 Linux Mint 17.1 64 位(未声明/非类型)上“制作”C++ 项目时从 cstdlib 编译错误和类似错误

Posted

技术标签:

【中文标题】尝试在 Linux Mint 17.1 64 位(未声明/非类型)上“制作”C++ 项目时从 cstdlib 编译错误和类似错误【英文标题】:Compile Errors from cstdlib and similar when trying to "make" C++-project on Linux Mint 17.1 64bit (not declared/not a type) 【发布时间】:2015-03-30 11:57:35 【问题描述】:

我有点坚持这一点。 我刚刚安装了一个带有 Linux Mint 的虚拟机,设置了我需要的各种库/包,但在尝试“制作”时遇到错误

由于我的项目需要 OpenCV,因此我按照以下说明进行包安装等: http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html

构建 OpenCV 本身没有任何问题,这就是为什么以下错误代码让我很惊讶......

在项目上使用 cmake 后,我尝试“制作”它并得到以下错误(为了清楚起见,仅选择了几个示例 - 完整的错误日志可在此处找到:http://pastebin.com/Ekn3szTb):

    /usr/include/x86_64-linux-gnu/bits/mathcalls.h:112:1: error: ‘log10’ was not declared in this scope
     __MATHCALL (log10,, (_Mdouble_ __x));
     ^
    /usr/include/x86_64-linux-gnu/bits/mathcalls.h:112:1: error: ‘__CONCAT’ cannot be used as a function
     __MATHCALL (log10,, (_Mdouble_ __x));
     ^
    /usr/include/x86_64-linux-gnu/bits/mathcalls.h:112:1: error: expected primary-expression before ‘)’ token
     __MATHCALL (log10,, (_Mdouble_ __x));

[...]

/usr/include/x86_64-linux-gnu/bits/mathcalls.h:195:1: error: expected primary-expression before ‘)’ token
 __MATHDECL_1 (int,__finite,, (_Mdouble_ __value)) __attribute__ ((__const__));
 ^
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:196:1: error: ‘__END_NAMESPACE_STD’ does not name a type
 _Mdouble_END_NAMESPACE
 ^
In file included from /usr/local/include/opencv2/core/types_c.h:94:0,
                 from /usr/local/include/opencv2/core/core_c.h:47,
                 from /usr/local/include/opencv/cv.h:63,
                 from /home/appuru/desktop/test/build/include/demo.h:4,

[...]

/usr/include/stdio.h:46:1: error: ‘__BEGIN_NAMESPACE_STD’ does not name a type
 __BEGIN_NAMESPACE_STD
 ^
/usr/include/stdio.h:49:1: error: ‘__END_NAMESPACE_STD’ does not name a type
 __END_NAMESPACE_STD

[..]

/usr/include/stdio.h:237:20: error: ‘FILE’ was not declared in this scope
 extern int fclose (FILE *__stream);
                    ^
/usr/include/stdio.h:237:26: error: ‘__stream’ was not declared in this scope
 extern int fclose (FILE *__stream);
[...]

等等……

如果不是所有错误,大多数错误似乎都来自通过“cv.h”(包含在我的头文件中)对标准 c++ 库的调用。

我已经在谷歌上搜索了很长一段时间,几乎尝试了所有与我的问题相关的方法,但没有任何解决方法。

我错过了什么? 我是 Linux 新手,这就是为什么我不太确定我还需要研究什么.. 我是否缺少某些包裹,还是需要指定其他内容?

/编辑:

这是 cmake 调用:

appuru@appuru-VirtualBox ~/desktop/test/build $ cmake ..
jsoncpp_FOUND = 1
jsoncpp_INCLUDES = /usr/local/include/json
jsoncpp_LIBRARIES = /usr/local/lib/libjsoncpp.a
OpenCV_LIBS = opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d
OpenCV_INCLUDE_DIRS = /usr/local/include/opencv;/usr/local/include
-- Configuring done
-- Generating done
-- Build files have been written to: /home/appuru/desktop/test/build

/edit2:

详细:

appuru@appuru-VirtualBox ~/desktop/test/build $ make VERBOSE=1
/usr/bin/cmake -H/home/appuru/desktop/test -B/home/appuru/desktop/test/build --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/appuru/desktop/test/build/CMakeFiles /home/appuru/desktop/test/build/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory »/home/appuru/desktop/test/build« 
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
make[2]: Entering directory »/home/appuru/desktop/test/build« 
cd /home/appuru/desktop/test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/appuru/desktop/test /home/appuru/desktop/test /home/appuru/desktop/test/build /home/appuru/desktop/test/build /home/appuru/desktop/test/build/CMakeFiles/test.dir/DependInfo.cmake --color=
make[2]: Quitting directory »/home/appuru/desktop/test/build« 
make -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
make[2]: Entering directory »/home/appuru/desktop/test/build« 
/usr/bin/cmake -E cmake_progress_report /home/appuru/desktop/test/build/CMakeFiles 1
[ 11%] Building CXX object CMakeFiles/test.dir/src/testDetector.cpp.o
/usr/bin/c++    -O3 -DNDEBUG -I/home/appuru/desktop/test/build/include -I/home/appuru/desktop/test/include -I/usr/local/include/opencv -I/usr/local/include -I/usr/local/include/json    -o CMakeFiles/test.dir/src/testDetector.cpp.o -c /home/appuru/desktop/test/src/testDetector.cpp

之后就像我之前发布的一样..?

CMakeLists.txt:

    CMAKE_MINIMUM_REQUIRED (VERSION 2.8)



    PROJECT (test)


    SET (LIBRARY_OUTPUT_PATH "$PROJECT_BINARY_DIR/lib")
    SET (EXECUTABLE_OUTPUT_PATH "$PROJECT_BINARY_DIR/bin")


    # The version number
    SET (test_VERSION_MAJOR 1)
    SET (test_VERSION_MINOR 0)
    SET (DEBUG false)


    # configure a header file to pass some of the CMake settings to the source code
    CONFIGURE_FILE (
        "$PROJECT_SOURCE_DIR/include/testConfig.h.in"
        "$PROJECT_BINARY_DIR/include/testConfig.h"
    )


    FILE(GLOB INCLUDES "$PROJECT_SOURCE_DIR/include/*.h")
    INCLUDE_DIRECTORIES ("$PROJECT_BINARY_DIR/include")
    INCLUDE_DIRECTORIES ("$PROJECT_SOURCE_DIR/include")


    SET (CMAKE_MODULE_PATH $CMAKE_MODULE_PATH "$PROJECT_SOURCE_DIR/cmake")
    FIND_PACKAGE (OpenCV REQUIRED)
    FIND_PACKAGE (jsoncpp REQUIRED)


    INCLUDE_DIRECTORIES ("$OpenCV_INCLUDE_DIRS")
    INCLUDE_DIRECTORIES ("$jsoncpp_INCLUDES")


FILE (GLOB SOURCES "$PROJECT_SOURCE_DIR/src/*.c*")
SET (SOURCES $SOURCES)


SET (CMAKE_BUILD_TYPE Release)
ADD_LIBRARY (test STATIC $SOURCES $INCLUDES)
FILE(COPY $INCLUDES DESTINATION "$PROJECT_BINARY_DIR/include")

TARGET_LINK_LIBRARIES (test $OpenCV_LIBS)
MESSAGE ("OpenCV_LIBS = $OpenCV_LIBS")
MESSAGE ("OpenCV_INCLUDE_DIRS = $OpenCV_INCLUDE_DIRS")
TARGET_LINK_LIBRARIES (test $jsoncpp_LIBS)

INSTALL (TARGETS test ARCHIVE DESTINATION lib LIBRARY DESTINATION lib COMPONENT library)
INSTALL (FILES $INCLUDES DESTINATION include/test)


#PROJECT (testDemo)

FILE (GLOB MARKERC_SRC "$PROJECT_SOURCE_DIR/tools/testDemo.cpp")
SET (MARKER_SRC $MARKERC_SRC)
ADD_EXECUTABLE (testDemo $MARKER_SRC)
TARGET_LINK_LIBRARIES (testDemo $OpenCV_LIBS)
TARGET_LINK_LIBRARIES (testDemo $jsoncpp_LIBS)
TARGET_LINK_LIBRARIES (testDemo $LIBRARY_OUTPUT_PATH/libtest.a)

【问题讨论】:

你可能应该向我们展示你的 cmake 是这么想的,但因为它没有任何意义,所以我没有这样做。秒,编辑它。 显示失败的 gcc 调用,以及所有命令行参数。 (CMAKE_VERBOSE_MAKEFILE 或 --trace)。 @Appuru,因为您在构建时遇到问题,请向我们展示文件,这是您构建的基础——CMakeLists 等。 你也可以编译和运行一个“hello world”c或c++程序吗? 【参考方案1】:

在设置 linux 2 次后,在构建项目的不同阶段仍然出现相同的错误,我找到了它的原因。

jsoncpp 使用名为 features.h 的标头,而标准 c++ 库也包含另一个 features.h。

无论出于何种原因,它对其他所有人都有效,但让我的计算机在构建库时选择了错误的头文件。我之前已经搜索过这个错误,发现它是由 jsoncpp 家伙修复的,但猜测不是所有可能的设置。

我现在使用 jsoncpp 的合并版本,不再与 cmake 链接。

【讨论】:

确实,编译器中没有针对此类错误的检测器。我被困了2天。 (而且不是json,是我自己的项目)。感谢您的帮助。 其实不是文件名有问题,而是include监护人:_FEATURES_H重命名通过。

以上是关于尝试在 Linux Mint 17.1 64 位(未声明/非类型)上“制作”C++ 项目时从 cstdlib 编译错误和类似错误的主要内容,如果未能解决你的问题,请参考以下文章

升级Linux Mint

Linux Mint x64:Qt 5.3.1 插件部署:不兼容的 qt 库

在 Linux Mint 19 Tara 上安装 Docker [关闭]

Eclipse ADT Bundle 在 Mint 16 Petra 上突然崩溃

linux mint18 cinnamon 64bit 安装 docker

Linux 内核 4.8.0-53-generic Linux Mint 64 位中 IOCTL 函数的不兼容指针初始化错误