How do you compile/build/execute a C++ project in Geany?
I really didn't think it would be this difficult. Geany clearly has the ability to create projects, add files to the projects, compile the individual files, but then even after googling it I could not find a clear开发者_如何学Python description of how to build and execute the project... It's pretty annoying because I really like the simplicity of Geany and its clean, uncluttered workspace, but this could be a deal breaker.
Geany doesn't compile projects. You can use a makefile to serve the same purpose; however, you have to make it manually or use an external command that can figure out dependencies. Geany's "make" command will use the make file called "makefile" by default, so you can simply give your make file that name and all should be well.
all: hello
hello: main.o factorial.o hello.o
g++ main.o factorial.o hello.o -o hello
main.o: main.cpp
g++ -c main.cpp
factorial.o: factorial.cpp
g++ -c factorial.cpp
hello.o: hello.cpp
g++ -c hello.cpp
clean:
rm -rf *o hello
Example taken from here. You can find more detailed information on that page as well.
To build project just open a file of the project, then choose Make in the Build menu (shift+F9).
For executing menu Build and Execute (F5).
If the project does not compile using make (as it usually does on Linux), you will also have to edit properties of the project in the menu Project entry Properties.
If you want details you could also read the manual, it could seems dumb compared to googling, but it looks quite clear to me... Just hit F1 key.
According to this, hit F8 to compile and F5 to run the project. You first have to setup the compiler though, as mentioned in the article.
Geany builds projects using external commands. This is flexible and allows the IDE to be language-agnostic, thus being able to build large and heterogeneous projects.
Regarding C++, it's very simple to create a basic Makefile (much simpler than the example above). Supose your project builds a program called "my_program", consists of the files my_program.cpp and bar.cpp, and links with the foo library. All you need is this:
LDLIBS += -lfoo
my_program: my_program.cpp bar.cpp
Save this with the name "Makefile" in the same directory of the sources.Now you have to create the Geany project proper, indicating that the base directory is where the code (and Makefile) are stored.
That's it! you can now compile you program with a keypress (shift+F9). For also running it with a key just enter your program name (my_program in the example) in the Geany's project properties.
Note that it's important that one of your source files has the same name as the target binary, otherwise you cannot user Make's implicit rules, wich complicates the Makefile a bit.
Compiling a multi-file C++ project using Geany's F-keys requires that you first setup a Makefile and the corresponding settings in Geany (as described in previous answers); after such setup is completed the F-keys in Geany's Build drop-down menu become useful for that particular multi-file project.
If however you just want to quickly compile a multi-file C++ project without having to setup a Makefile as well as Geany's settings, use the terminal at the bottom of Geany to type the command-line instruction for compiling a multi-file project:
uberstudent@uberstudent:~$ g++ my_source1.cpp my_source2.cpp -o my_executable
You can then execute your executable with:
uberstudent@uberstudent:~$ ./my_executable
(Note that the above applies to Geany on Linux; I have not tested the above commands on other operating systems.)
Assuming you set up your paths(right-click my computer > properties > advanced system settings > environment variables
, just google search what to do next) and Mingw correctly, click on "set build menu commands" and enter the following. including the "".
compile = g++ -O0 -g3 -Wall -c -o"%e.o" "%f"
Build = g++ -o"%e" ./%e.o
Execute = "./%e"
this is what worked for me, if you get an error when trying to build (after you compiled) that says something about some permissions issue, that is b/c of windows UAC is blocking Geany from building. You just need to run geany as admin to resolve this.
精彩评论