G ++输出:文件无法识别:文件格式无法识别 [英] g++ output: file not recognized: File format not recognized

查看:3715
本文介绍了G ++输出:文件无法识别:文件格式无法识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立与首次多个文件程序。
我从未有过任何问题仅有的main.cpp compliling程序。
随着下面的命令,这是结果:

I am trying to build program with multiple files for the first time. I have never had any problem with compliling program with main.cpp only. With following commands, this is the result:

$ g++ -c src/CNumber.cpp src/CNumber.h -o src/CNumber.o
$ g++ -c src/CExprPart.cpp src/CExprPart.h -o src/CExprPart.o
$ g++ -c src/CExpr.cpp src/CExpr.h -o src/CExpr.o
$ g++ -c src/main.cpp -o src/main.o
$ g++ src/CNumber.o src/CExprPart.o src/CExpr.o src/main.o -o execprogram
src/CNumber.o: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

什么会导致这样的错误,我应该怎么办呢?
使用Linux Mint的使用GCC(Ubuntu的/ Linaro的4.7.2-2ubuntu1)。
谢谢

What could cause such error and what should I do with it? Using Linux Mint with gcc (Ubuntu/Linaro 4.7.2-2ubuntu1). Thank you

推荐答案

这是错误的:

 g++ -c src/CNumber.cpp src/CNumber.h -o src/CNumber.o

您不应该编译.h文件。这样做将创建precompiled头文件,它不用于创建可执行文件。
以上应该简单地

You shouldn't "compile" .h files. Doing so will create precompiled header files, which are not used to create an executable. The above should simply be

 g++ -c src/CNumber.cpp o src/CNumber.o

编译其他.cpp文件类似

Similar for compiling the other .cpp files

这篇关于G ++输出:文件无法识别:文件格式无法识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆