相关疑难解决方法(0)

什么是未定义的引用/未解析的外部符号错误,我该如何解决?

什么是未定义的参考/未解决的外部符号错误?什么是常见原因以及如何修复/预防它们?

随意编辑/添加您自己的.

c++ c++-faq linker-errors unresolved-external undefined-reference

1418
推荐指数
32
解决办法
52万
查看次数

如何转发声明名称空间中的类

我试图在头文件中使用前向声明来减少使用的#includes,从而减少用户包含我的头文件的依赖关系.

但是,我无法转发使用命名空间的decalre.见下面的例子.

a.hpp file:
#ifndef __A_HPP__
#define __A_HPP__

namespace ns1 {

   class a {
   public:
      a(const char* const msg);

      void talk() const;

   private:
      const char* const msg_;
   };
}

#endif //__A_HPP__

a.cpp file:
#include <iostream>

#include "a.hpp"

using namespace ns1;

a::a(const char* const msg) : msg_(msg) {}

void a::talk() const { 
   std::cout << msg_ << std::endl; 
}



consumer.hpp file:
#ifndef __CONSUMER_HPP__
#define __CONSUMER_HPP__

// How can I forward declare a class which uses a namespace
//doing this below results in …
Run Code Online (Sandbox Code Playgroud)

c++ namespaces

38
推荐指数
2
解决办法
4万
查看次数

未解析的外部符号“std::basic_string”

我正在尝试通过 Visual C++ 编译器使用 Maven 编译一个项目,并且我不断收到有关 std::basic_string 类的链接错误。我确保将 <string> 头文件包含到相应的 c++ 文件中。

我错过了什么还是我犯了一个愚蠢的错误???请让我知道我哪里出错了。

[ERROR] Parsor.obj : error LNK2001: unresolved external symbol

"__declspec(dllimport) public:
    int __thiscall std::basic_string<
        char,
        struct std::char_traits<char>,
        class std::allocator<char> >::compare(
            class std::basic_string<
                char,
                struct std::char_traits<char>,
                class std::allocator<char> > const &) const"

(__imp_?compare@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEHABV12@@Z)
Run Code Online (Sandbox Code Playgroud)

c++ std linkage visual-c++ maven

6
推荐指数
1
解决办法
9752
查看次数

Linux 共享库中缺少函数

我支持一个 Linux 程序,该程序允许用户编写自己的基于 .so 文件的插件,这些插件在运行时使用 dlopen() 加载。有时用户会忘记在包含必要函数定义的 makefile 中包含一个 C++ 文件。当插件管理器使用 dlsym() 从依赖于这些缺失函数定义之一的插件加载导出函数时,我得到一个空函数地址。

我的问题:我怎样才能提前检测到这个错误?我试过 -z defs 和 -Wno-undef 链接器标志,但它们不会产生错误。我已经尝试了带有各种标志的 nm、readelf 和 objdump 命令,但是未定义的函数根本没有出现在符号表中。有什么建议?谢谢!

c++ linux g++ shared-libraries

5
推荐指数
1
解决办法
646
查看次数

未解决的外部链接2019年混乱

我正在尝试解决未解决的外部问题(link2019 错误)。StackOverflow 上有很多关于这个问题的帖子,但要么我不理解这个错误,要么我对它视而不见。

该错误是由我的generate_maze函数引起的(特别是由rand_neighbor()调用引起的,对吧?)但我的理解是这些都已“解决”。

我稍微截断了代码,因为它非常冗长。我希望这是合适的。

void generate_maze (Vector<int> &coords, Grid<bool> &included, Maze &m);

int main() {

    Grid<bool> included = initialize_grid();
    Vector <int> coords = rand_coords();
    Vector <int> current_point = coords;

    generate_maze(coords, included, m);
    return 0;
}

void generate_maze (Vector<int> &coords, Grid<bool> &included,  Maze &m) {
    while (gridIsTrue == false) {
    Vector<int> neighbor = rand_neighbor(coords, included);
    pointT neighborpoint = {neighbor[0], neighbor[1]};
    pointT current_point = {coords[0], coords[1]};
    if (included.get(neighbor[0], neighbor[1]) == false) {m.setWall(current_point, neighborpoint, false); included.set(neighbor[0], neighbor[1], true); current_point = neighborpoint;}
    } …
Run Code Online (Sandbox Code Playgroud)

c++ unresolved-external

3
推荐指数
1
解决办法
1万
查看次数

受保护的函数调用c ++

Class Base() {
protected:
    void foo();
}
Class Derived : public Base {
    void bar();
}

void Derived::bar(){
    foo();    //this causes an error.
}
Run Code Online (Sandbox Code Playgroud)

我知道我可能错过了一些明显的东西,但我已经绕圈了一个小时.如何在派生类中调用受保护的函数?

c++ inheritance

-2
推荐指数
1
解决办法
979
查看次数