【发布时间】:2014-11-16 20:00:20
【问题描述】:
我无法运行使用 MinGW-w64 和 Eclipse 作为 IDE 构建的程序。一旦我运行它,控制台中没有任何输出,来自 Windows appers 的消息“myprog.exe 已停止工作”。代码很好,但是当我排除构建特定文件时它可以工作。
我个人的猜测是和代码无关(因为我在另一个项目中测试过),是代码文件的组合导致了这个问题。 在 Eclipse 的调试透视图中告诉我
没有可用于“libstdc++-6!_ZSt9use_facetISt9money_putIwSt19ostreambuf_iteratorIwSt11char_traitsIwEEEERKT_RKSt6locale() at 0x6fcb9c0a”的源代码
有人建议在链接器选项中添加这些标志:
-static-libstdc++ -static-libgcc
它不起作用,但错误消息不同:
没有可用于“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;}
“一元”类完全相同,但不会导致程序失败
【问题讨论】:
-
我的猜测是您的代码是有问题。有时,您的程序可以使用一个工具链,但在另一个工具链中失败,但它一开始只是偶然的。您的堆可能已损坏。
-
有关缺少源的消息应该来自调试器,并且仅在程序首先崩溃时才会出现。
-
如何验证执行是否到达 main(我是 C/C++ 新手)?
-
看起来崩溃发生在
main()之前,此时正在调用全局构造函数。我这样说是因为__do_global_ctors()在堆栈跟踪中。 -
但这也是“__do_global_ctors() at 0x405245”的无源代码
标签: c++ gcc dll linker mingw-w64