c++ - "libstdc++-6..."没有可用的源

标签 c++ gcc dll linker mingw-w64

我无法运行使用 MinGW-w64 和 Eclipse 作为 IDE 构建的程序。一旦我运行它,控制台中没有任何输出,Windows 应用程序就会显示消息“myprog.exe 已停止工作”。代码很好,但是当我从构建特定文件中排除时它可以工作。

个人猜测与代码无关(因为我在另一个项目中测试过),是代码文件的组合导致了这个问题。 在 Eclipse 的调试角度告诉我

No source available for "libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale() at 0x6fcb9c0a"

No source available for "libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale() at 0x6fcb9c0a" 有人建议在链接器选项中添加这些标志:

-static-libstdc++ -static-libgcc

它没有用,但错误消息不同:

No source available for "std::local_Rb_tree_decrement() at 0x47379a"

No source available for "std::local_Rb_tree_decrement() at 0x47379a"

主要是一个简单的 Hello World 打印。

命令:

21:01:55 **** Rebuild of configuration Debug for project autoMath ****
Info: Internal Builder is used for build
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\Operator.o ..\core\Operator.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o autoMath.o ..\autoMath.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operand\Integer.o ..\core\operand\Integer.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operand\Variable.o ..\core\operand\Variable.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operand\Constant.o ..\core\operand\Constant.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operand\Vector.o ..\core\operand\Vector.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operand\OperandCore.o ..\core\operand\OperandCore.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\Op.o ..\core\Op.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operator\Unary.o ..\core\operator\Unary.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operator\OperatorCore.o ..\core\operator\OperatorCore.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\operator\Binary.o ..\core\operator\Binary.cpp 
g++ -std=c++1y -O0 -g3 -Wall -c -fmessage-length=0 -o core\Operand.o ..\core\Operand.cpp 
g++ -static-libstdc++ -static-libgcc -o autoMath core\operator\Unary.o core\operator\OperatorCore.o core\operator\Binary.o core\operand\Vector.o core\operand\Variable.o core\operand\OperandCore.o core\operand\Integer.o core\operand\Constant.o core\Operator.o core\Operand.o core\Op.o autoMath.o

编辑:导致执行失败的文件的源代码

//Binary.hpp
#include "OperatorCore.hpp"
#include "../../utility/StaticPool.hpp"
class Binary final : public OperatorCore, public StaticPool<Binary> {
    friend class StaticPool<Binary>;
public:
    enum IDs {SUM = 0, SUB, MUL, DIV, POW};
protected:
    Binary(IDs ID, std::string name, int precedence, bool revOrder = false);
public:
    const bool isAssociative;
    const bool revOrder;
    ~Binary();
    std::string print(bool latex = false) const;
    operator int() const;
};
//Binary.cpp
#include "Binary.hpp"
template<>
const Binary StaticPool<Binary>::pool[] = {
        {Binary::SUM, "+", 1}//deleting this line fix the problem
};
Binary::Binary(IDs ID, std::string name, int precedence, bool revOrder) :
        OperatorCore(name, precedence, name), StaticPool<Binary>(ID), isAssociative(true), revOrder(revOrder) {}
Binary::~Binary() {}
std::string Binary::print(bool latex) const {return name;}
Binary::operator int() const {return ID;}

“一元”类完全相同,但不会使程序失败

最佳答案

您可以忽略“无可用资源”消息。您收到此消息是因为您正在使用调试器查看正在执行标准库中的函数的堆栈帧,而标准库的源代码不可用。源代码不可用没关系,因为该错误可能无论如何都不在标准库中。

在您的工具链中遇到真正的错误是非常罕见

如何读取堆栈跟踪

我创建了一个在我的系统上崩溃的小程序。

#include <vector>
#include <algorithm>

int main() {
    std::vector<int> v { 9, 8, 7, 6, 5, 4, 3 };
    std::sort(std::begin(v), std::begin(v) + 16);
    return 0;
}

当我在 gdb 中运行它时,我得到以下堆栈跟踪:

#0  0x00007ffff7246107 in __GI_raise (sig=sig@entry=6)
    at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff72474e8 in __GI_abort () at abort.c:89
#2  0x00007ffff7284044 in __libc_message (do_abort=do_abort@entry=1, 
    fmt=fmt@entry=0x7ffff7376c60 "*** Error in `%s': %s: 0x%s ***
")
    at ../sysdeps/posix/libc_fatal.c:175
#3  0x00007ffff728981e in malloc_printerr (action=1, 
    str=0x7ffff7376e20 "free(): invalid next size (fast)", ptr=<optimized out>)
    at malloc.c:4996
#4  0x00007ffff728a526 in _int_free (av=<optimized out>, p=<optimized out>, 
    have_lock=0) at malloc.c:3840
#5  0x0000000000401456 in __gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long) ()
#6  0x00000000004010ca in std::allocator_traits<std::allocator<int> >::deallocate(std::allocator<int>&, int*, unsigned long) ()
#7  0x0000000000400dba in std::_Vector_base<int, std::allocator<int> >::_M_deallocate(int*, unsigned long) ()
#8  0x0000000000400b95 in std::_Vector_base<int, std::allocator<int> >::~_Vector_base() ()
#9  0x0000000000400a6b in std::vector<int, std::allocator<int> >::~vector() ()
#10 0x0000000000400878 in main ()

您可以看到第 10 帧在我的代码中,但第 0-9 帧在标准库中。这是比较正常的。您还会注意到,崩溃是在错误代码执行完毕后发生的:对 std::sort() 的调用是导致崩溃的原因,但崩溃并没有直到 main() 返回。

调试崩溃可能非常棘手。

查找错误的工具

您正在使用 MinGW,它是 GCC,这意味着您可能可以访问地址清理器。尝试将 -fsanitize=address 添加到调试版本的编译和链接标志中。

当我用 -fsanitize=address 编译我的测试程序时,程序在 std::sort() 中崩溃,这更接近实际错误所在在 main() 中。地址清理器将使您的程序更快崩溃,从而更容易调试。

类似的工具是 Valgrind。

哪里出错了?

我只能猜测,因为我看不到您的任何源代码。但看起来 Binary 的构造函数中存在错误,或者以错误的方式构造了类型为 Binary 的全局变量。请记住,全局变量可以按任何顺序初始化,因此如果使用任何尚未初始化的全局变量,您的代码可能会崩溃。这是 C++ 程序中极其常见的错误来源。

关于c++ - "libstdc++-6..."没有可用的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26961424/

相关文章:

c# - 在 C# 中使用特定版本的 dll

c++ - 删除大小为 1 的数组

c++ - 并发 STL it++ 和 *it 安全吗?

c++ - 如何使用 G++ 抑制纯虚拟类的 C++ vtable 生成?

c - 打印整数值时出现意外输出

c++ - vc++2008 安装程序项目 msvcrt.dll

c++ - 为什么我的变量超出了它的范围

c++ - 在 C++ 中使用 find_if() 函数

linux - Ubuntu/usr/bin/ld : cannot find -lsasl2 while installing monary

c++ - 创建dll文件是否一定要写头文件?