没有可用于“libstdc ++ - 6 ......”的来源

时间:2014-11-16 20:00:20

标签: c++ gcc dll linker mingw-w64

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

我个人的猜测是它与代码无关(因为我在另一个项目中测试过),它是导致此问题的代码文件的组合。 在Eclipse的调试透视图中为我提供了

  

没有来源可用于" libstdc ++ - 6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale()位于0x6fcb9c0a"

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

-static-libstdc++ -static-libgcc

它没有用,但错误的信息是不同的:

  

没有可用于" std :: local_Rb_tree_decrement()的源位于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;}

Class&#34;一元&#34;是完全相同但它不会使程序失败

1 个答案:

答案 0 :(得分:2)

您可以忽略&#34;没有可用的来源&#34;信息。您收到此消息是因为您正在使用调试器查看正在执行标准库中的函数的堆栈帧,并且标准库的源代码不可用。可以使用源代码,因为错误可能不在标准库中。

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

如何读取堆栈跟踪

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

#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 ++程序中非常常见的错误来源。