"<某些系统标头>:错误:"<在此处插入函数>"在移动源文件后不是"std"的成员

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

本文关键字:gt lt 源文件 移动 成员 std 函数 插入 错误 系统      更新时间:2023-10-16

在将源文件从我的项目移动到子目录之后,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.

我确实通过包括&lt来设法"解决"了该问题;字符串>在所述标题文件中,但是出现了一个新的,甚至怪异的错误。

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.

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

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 Include路径来完成。看起来您添加了将代码也放在该路径上的编译标志。也许像-I.一样无辜的东西?

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