为什么我必须双运行make来完全编译我的程序? GNU c ++ [英] Why do I have to double run make to fully compile my program? GNU c++
问题描述
在我的学校服务器上,我只是使用gcc和几乎相同的代码每次我
我下载了我的程序以在NetBeans中调试它,并在几个小时/天后。我终于ALMOST一切正常了。
在看到这里和其他网站上的几个帖子后,我看到由于某种原因,我需要使用g ++而不是gcc编译,因为我使用的是MacBook。我真的不明白..但如果我将gcc更改为g ++并在我的makefile中运行这行:
编辑:
g ++ -c $< -o $ @ -std = c ++ 0x -lstdc ++
但是如果我删除-std = c ++ 0x并运行make again。一切都很好。
但是如果我运行make clean必须重新做。
当我把程序放回我的学校服务器时,这会混乱吗?或者应该没问题,只要我有一个makefile在不同于我的MacBook上的makefile的服务器上。
有人可以帮助驱逐为什么会发生这种情况,我可以修复它吗?
这是我第一次运行make时的makefile:
code> OBJECTS = Ammunition.o Armor.o Consumable.o
HEADERS = Ammunition.h Armor.h Consumable.h
all:Jhack
%.o:%.cpp $(HEADERS)
g ++ -c $< -o $ @ -std = c ++ 0x
Jhack:$(OBJECTS)main.o
g ++ -o Jhack $ ^
clean:
rm -f * .o Jhack
运行:Jhack
./Jhack
b $ b
感谢。
首先,对于Linux GNU C编译器, gcc 一个C编译器,而 g ++ 是一个C ++编译器。这意味着当你使用gcc进行编译时,所有的错误信息基本上都是我不知道这个奇怪的语法是什么。
你的学校不是使用Linux服务器,或者gcc可能有一个链接到c ++编译器。或者核心make规则正在用g ++替换你的编译器选择。
我不认为在这方面你需要担心。只要记住差异,并且可能用你的makefile中的宏替换gcc和g ++。
至于-std选项,它选择你想要的C ++标准版本编译反对。由于您的一些代码需要2011 C ++标准,您需要使用-std选项指定。如果你看看你的g ++手册页,它应该告诉你支持什么选项。
你可以尝试 -std = c ++ 0x
或 -std = c ++ 11
或 -std = gnu ++ 11
p>
任何一个都应该给你所需要的功能。根据我的搜索,你不需要指定 -std = stdc ++
,因为我认为默认包括g ++。
Im terrible with understanding what goes on behind the scenes when running programs.
On my schools server, I just use gcc and pretty much the same code every time I need to make a makefile lol.
I downloaded my program to debug it in NetBeans and after hours/days.. I finally ALMOST have everything working.
After looking at a few posts on here and other sites, I saw that for some reason I need to use g++ instead of gcc to compile since I'm using a MacBook. Which I don't really understand.. But if I change gcc to g++ and run this line in my makefile:
Edit:
g++ -c $< -o $@ -std=c++0x -lstdc++
I get an error. But if I remove "-std=c++0x" and run make again.. Everything is good to go.
But if I run my "make clean" I have to do it over again..
Will this mess everything up when I put the program back on my schools server? Or should it be fine as long as I have a makefile on the server that is different from the makefile on my MacBook?
Can someone help expelling why this is happening and how I could possibly fix it?
Here's my makefile the first time I run make:
OBJECTS = Ammunition.o Armor.o Consumable.o
HEADERS = Ammunition.h Armor.h Consumable.h
all: Jhack
%.o: %.cpp $(HEADERS)
g++ -c $< -o $@ -std=c++0x
Jhack: $(OBJECTS) main.o
g++ -o Jhack $^
clean:
rm -f *.o Jhack
run: Jhack
./Jhack
Thanks.
First, for Linux GNU C compilers, gcc is a C compiler whereas g++ is a C++ compiler. Which means when you compile with gcc, all your error messages are basically saying, "I don't know what all this strange syntax is."
Your school isn't using a Linux server, or "gcc" there may be a link to a c++ compiler. Or the core make rules are replacing your compiler choice with g++.
I don't think there's all that much you need to worry about in this regard. Just remember the difference, and possibly replace gcc and g++ with a macro in your makefile.
As for the -std option, that's choosing which version of the C++ standard you want to compile against. Since some of your code requires 2011 C++ standard, you need to specify that with your -std option. If you look at your g++ man pages, it should tell you what options are supported.
You can try -std=c++0x
or -std=c++11
or -std=gnu++11
Any of those should give you the functionality you require. Based on what I've searched for, you don't need to specify -std=stdc++
since i think that's included by g++ by default.
这篇关于为什么我必须双运行make来完全编译我的程序? GNU c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!