程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp?

开发过程中遇到C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp的问题如何解决?下面主要结合日常开发的经验,给出你关于C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp的解决方法建议,希望对你解决C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp有所启发或帮助;

对于个人项目,树莓派控制的吉他踏板,我正在创建一个小型图书馆。这个库包含一堆类,指定了几种类型效果的功能。为此,我有一个 Effect 基类,每个效果都继承自,以及一个 EffectFactory 基类,它将根据配置文件创建效果序列。我使用的是 C++,这是一种我很陌生的语言,因为我通常使用 JavaScript。

EffectFactory 由映射到其他 EffectFactory 实例的指针和两个函数的字符串映射组成;一个负责将 EffectFactory 实例注册到工厂映射,另一个是可以被 EffectFactory 实例覆盖的创建函数。 当我编译库进行测试时出现了我的问题。我收到一个错误:

undefined reference to `EffectFactory::factorIEs[abi:cxx11]'

使用 c++11 ABI 似乎存在问题。我再次运行编译器并添加了 -Wabi-tag 并得到:

effect-master/effect.h:22:7: warning: 'EffectFactory' does not have the "cxx11" ABI tag that 'std::string' {aka 'std::__cxx11::basic_String<char>'} (used in the type of 'virtual Effect* EffectFactory::create(std::string)') has [-Wabi-tag]
   22 | class EffectFactory
      |       ^~~~~~~~~~~~~
effect-master/effect.h:26:19: note: 'virtual Effect* EffectFactory::create(std::string)' declared here
   26 |   virtual Effect *create(std::string config);
      |                   ^~~~~~
In file included from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\String:55,from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\locale_classes.h:40,from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\ios_base.h:41,from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\ios:42,from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\ostream:38,from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\iostream:39,from effect-master/effect.h:4,from effect-master/effect.cpp:1:
f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\basic_String.h:77:11: note: 'std::string' {aka 'std::__cxx11::basic_String<char>'} declared here
   77 |     class basic_String
      |           ^~~~~~~~~~~~
In file included from effect-master/effect.cpp:1:
effect-master/effect.h:29:49: warning: 'EffectFactory::factorIEs' inherits the "cxx11" ABI tag that 'std::map<std::__cxx11::basic_String<char>,EffectFactory*>' (used in its typE) has [-Wabi-tag]
   29 |   static std::map<std::string,EffectFactory *> factorIEs;
      |                                                 ^~~~~~~~~
In file included from f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\map:61,from effect-master/effect.h:6,from effect-master/effect.cpp:1:
f:\programs\mingw\lib\gcc\mingw32\9.2.0\include\c++\bits\stl_map.h:100:11: note: 'std::map<std::__cxx11::basic_String<char>,EffectFactory*>' declared here
  100 |     class map
      |           ^~~

据我所知,EffectFactorystd::stringstd::map 之间似乎存在某种不兼容。我花了一些时间谷歌搜索并找到了使用 -D_GliBCXX_USE_CXX11_ABI=0 的解决方案,但这并没有解决它。我还发现了 this 问题,但我无法理解它,也不知道它是否适用于我的情况。谁能帮助我理解并解决这个问题?

作为参,我使用的是 MinGW g++ 编译器。

效果.h

#ifndef EFFECT_H
#define EFFECT_H

#include <iostream>
#include <String>
#include <map>
#include <regex>

class EffectFactory;

class Effect
{
public:
  bool enabled = true;
  voID toggleEnabled();
  virtual voID triggerAction();
  virtual int eval(int input_signal);

protected:
  int output_signal;
};
class EffectFactory
{
public:
  static voID registerType(const std::string &name,EffectFactory *factory);
  virtual Effect *create(std::string config);

private:
  static std::map<std::string,EffectFactory *> factorIEs;
};

#endif

效果.cpp

#include "effect.h"

voID Effect::toggleEnabled()
{
  enabled = !enabled;
};
voID Effect::triggerAction()
{
  std::cout << "The base triggerAction was triggered\n";
};
int Effect::eval(int input_signal)
{
  std::cout << "The base eval was triggered\n";
  return input_signal;
};

Effect *EffectFactory::create(std::string config)
{
  std::smatch name_match;
  std::regex name_regex("^\\S+(?:\\n?)");
  std::regex replace_regex("^\\S+\\n?|^ {2}");
  std::regex_search(config,name_match,name_regeX);
  config = std::regex_replace(config,replace_regex,"");
  return factorIEs[name_match.str()]->create(config);
};
voID EffectFactory::registerType(const std::string &name,EffectFactory *factory)
{
  factorIEs[name] = factory;
};

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp全部内容,希望文章能够帮你解决C++ 未定义引用,类没有“std::string”具有的“cxx11”ABI 标记 效果.h效果.cpp所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: