“执行格式错误"运行由g ++创建的二进制文件 [英] "Exec format error" running a binary created by g++
问题描述
我的QTCreator生成的Makefile有问题.一切正常,除非当我尝试为自己的测试创建一个新的可执行文件时,我的终端说: bash:./RunTests:无法执行二进制文件:Exec格式错误
I have a problem with my QTCreator-generated Makefile. Everything is working fine except when I try to create myself a new executable file for my tests, my terminal says: bash: ./RunTests: cannot execute binary file: Exec format error
这是我的MakeFile规则的样子:
TESTS: ../WannaBeRPG/testes.cpp ../WannaBeRPG/hero.h ../WannaBeRPG/charinterface.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o RunTests ../WannaBeRPG/testes.cpp
标志是:
CXX = g++
CXXFLAGS = -pipe -g -std=gnu++0x -Wall -W -fPIC $(DEFINES)
INCPATH = -I../WannaBeRPG -I. -I/usr/lib64/qt5/mkspecs/linux-g++
DEFINES = -DQT_QML_DEBUG
如果这对我有帮助,请访问我的testes.cpp文件:
If that is anyhow helpful here is my testes.cpp file:
#include <gtest/gtest.h>
#include "hero.h"
TEST(teee, HPTEST)
{
Hero myHero("Hika",150,100,0,0,0,0,0,0,0);
EXPECT_EQ(100,myHero.getHP());
}
int main_tests(int argc, char* argv[])
{
testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
我正在使用Fedora.有什么想法为什么这样工作吗?此Makefile的主要执行程序完全正常.
I am using Fedora. Any ideas why does this works this way? Primary exec from this Makefile works completely fine.
推荐答案
g ++
的 -c
参数告诉它不要链接您的二进制文件.因此,您的输出文件是目标文件而不是可执行文件.
The -c
argument to g++
tells it not to link your binary. Thus, your output file is an object file rather than an executable.
这篇关于“执行格式错误"运行由g ++创建的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!