'<some system header>: error: ‘<insert function here>’ is not a member of ‘std’ ' after moving source file

'<some system header>: error: ‘<insert function here>’ is not a member of ‘std’ ' after moving source file

在将源文件从我的项目移动到子目录后,gcc 吐出一个奇怪的错误(它之前编译得很好)

make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
  CXX      main.o
In file included from /usr/include/c++/9/bits/stl_algobase.h:69,
                 from /usr/include/c++/9/memory:62,
                 from /usr/include/c++/9/memory_resource:37,
                 from main.h:5,
                 from main.cpp:1:
./debug/debug.h:14:28: error: variable or field ‘debug_queue_addN’ declared void
   14 | void debug_queue_addN(std::string msg);
      |                            ^~~~~~
compilation terminated due to -Wfatal-errors.

我确实通过在所述头文件中包含 设法 'resolve' 这个问题,但是出现了一个新的甚至更奇怪的错误。

make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
  CXX      main.o
In file included from /usr/include/c++/9/bits/stl_algobase.h:69,
                 from /usr/include/c++/9/memory:62,
                 from /usr/include/c++/9/memory_resource:37,
                 from main.h:5,
                 from main.cpp:1:
./debug/debug.h:14:28: error: variable or field ‘debug_queue_addN’ declared void
   14 | void debug_queue_addN(std::string msg);
      |                            ^~~~~~
compilation terminated due to -Wfatal-errors.

在这一点上,我什至尝试在任何其他地方包含之前包含 < algorithm >,但它根本没有帮助。相反,它抛出了这个更奇怪的错误...

make[3]: Entering directory '/home/rd/Desktop/fh/bf4/bbx/o4x/server/server_app/src'
  CXX      main.o
In file included from /usr/include/c++/9/bits/basic_string.h:48,
                 from /usr/include/c++/9/string:55,
                 from ./debug/debug.h:4,
                 from /usr/include/c++/9/bits/stl_algobase.h:69,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from main.cpp:2:
/usr/include/c++/9/string_view: In member function ‘std::basic_string_view<_CharT, _Traits>::size_type std::basic_string_view<_CharT, _Traits>::copy(_CharT*, std::basic_string_view<_CharT, _Traits>::size_type, std::basic_string_view<_CharT, _Traits>::size_type) const’:
/usr/include/c++/9/string_view:260:32: error: ‘min’ is not a member of ‘std’; did you mean ‘minus’?
  260 |  const size_type __rlen = std::min(__n, _M_len - __pos);
      |                                ^~~
      |                                minus
compilation terminated due to -Wfatal-errors.

现在,有人知道为什么会发生这种情况/我能做些什么来解决这个问题吗?

此外,这是错误输出中提到的代码。

main.cpp

#include "main.h"
#include "server.h"
#include "config.h"
#include "debug/debug.h"
#include "pidfile.h"
#include "messages.h"

#include <cstring>
#include <iostream>
#include <thread>
#include <algorithm>
[CUT HERE]

main.h

#ifndef __MAIN_H___
#define __MAIN_H___

#define __cpp_transactional_memory 0
#include <memory_resource>
extern std::pmr::synchronized_pool_resource* _upstream_resource;
extern std::pmr::pool_options _general_pool_options;

#endif

debug/debug.h

#ifndef __DEBUG_H__
#define __DEBUG_H__ 1

#include <string> // I added this as a 'solution' to the first mentioned problem
#include "config.h"

#ifdef DEBUGBUILD
#define dbg_out(a) debug_queue_addN(a)
#define dbg_sout(func, msg) this->debug_queue_add(func, msg)
#define dbg_csout(inh, func, msg) debug_queue_addI(inh, func, msg)
#define fatal_err_out(a) std::cout << a

void debug_print();
void debug_queue_addN(std::string msg);
void debug_queue_addI(std::string inh, std::string func, std::string msg);
#else
#define dbg_out(a)
#define dbg_sout(func, msg)
#define dbg_csout(inh, func, msg)
#define fatal_err_out(a) std::cerr << a
#endif

#endif

最后 Makefile.am

SUBDIRS =

EXTRA_DIST =

bin_PROGRAMS =
#check_PROGRAMS =
#TESTS =

GENERAL_GCC_FLAGS = -std=gnu++17 \
    -Og -falign-functions \
    -falign-jumps -falign-labels \
    -falign-loops -fwrapv \
    -fbranch-target-load-optimize \
    -fasynchronous-unwind-tables \
    -fcode-hoisting -fdce -fdse \
    -fgcse -fhoist-adjacent-loads \
    -fipa-icf -fipa-cp -fipa-pta -fipa-vrp \
    -fplt -fpeephole -freorder-functions \
    -fstack-protector-all -m80387 -mhard-float \
    -malign-double -mcld -mcx16 -msahf -mmovbe -mcrc32 \
    -mrecip -mprefer-avx128 -mmmx -msse4.2 -mavx512vbmi \
    -msha -maes -mrdrnd -mf16c -pthread -mpc80 -m64 -g3 -fconcepts \
    [CUT OUT a whole lot of -Wxxxxx]
#   --param asan-stack=1 --param asan-instrument-allocas=1 \
#   --param asan-globals=1 --param asan-instrument-writes=1 \
#   --param asan-instrument-reads=1 --param asan-memintrin=1 \
#   --param asan-use-after-return=1 --param asan-instrumentation-with-call-threshold=1 \
#   -fsanitize=address

GENERAL_FLAGS = $(GENERAL_GCC_FLAGS)

AM_CFLAGS = $(WARNCFLAGS) $(GENERAL_FLAGS)
AM_CXXFLAGS = $(WARNCXXFLAGS) $(CXX1XCXXFLAGS) $(GENERAL_FLAGS)
AM_CPPFLAGS = $(GENERAL_FLAGS)

LDADD = @LIBXML2_LIBS@ \
    @LIBEV_LIBS@ \
    @OPENSSL_LIBS@ \
    @SYSTEMD_LIBS@ \
    @JANSSON_LIBS@ \
    @ZLIB_LIBS@ \
    @APPLDFLAGS@

bin_PROGRAMS += server_app

server_class_packetEx_SOURCES = packets/dcs_do.cpp packets/hbp_do.cpp packets/ack_do.cpp 
server_class_SOURCES = server.cpp perform_commands.cpp handle_commands.cpp server_message_byte_strs.cpp \
    networking.cpp messages.cpp packet_check.cpp send_packages.cpp errors.cpp $(server_class_packetEx_SOURCES)
auth_class_SOURCES = auth/authentication.cpp
debug_SOURCES = debug/debug.cpp

server_app_SOURCES = main.cpp export.cpp pidfile.cpp $(server_class_SOURCES) $(auth_class_SOURCES)

if DEBUGBUILD
server_app_SOURCES += $(debug_SOURCES)
endif

从错误来看,您的 debug/debug.h 似乎正在被 /usr/include/c++/9/bits/stl_algobase.h 拾取。这与实际的 /usr/include/c++/9/debug/debug.h.

冲突

至少在我的系统上,这些包含是使用 #include <...> 形式完成的,即通过搜索 system 包含路径。看起来您添加了将代码也放在该路径上的编译标志。也许像 -I. 一样天真?

要解决此问题,您应该删除额外的 -I 标志或重命名您的 debug/debug.h 文件。