# New to Linux based programming

## Recommended Posts

I just recently installed Ubuntu on a virtual machine and I got Eclipse Helios C++ IDE running with the most current version of G++. Everything checked out good and working with a simple console program. I am looking at doing something like this but not too sure where to start as I am new to the whole makefile thing. I want to be able to make a makefile based command line application that will implement two passive event driven state machines with a main loop to drive them. I am looking to be pointed in the right direction or some tips/hints to get me started, please talk to me like I am new to everything since using the Linux environment for programming and makefiles are completely new to me. Any help is much appreciated and thank you in advance.

##### Share on other sites
Well I was on ubuntu for awhile and am now on debian and what I have learned is that it is almost easier to skip the makefile and just make a script. Now I would recommend trying to use the command line for almost everything for awhile to truely get used to it and maybe even use vim or vi as a text editor. Then once you know how to use the command line, you can start developing applications on it. What you will be using is g++ to compile. Ex.
g++ -o ProgramName (source files) main.cpp engine.cpp camera.cpp (then linker flags) -lGL -lsfml-window -lsfml-graphics
Then once you know how to compile your own projects on the command line, you can start making scripts or makefiles (I personally like scripts better). Now here is a small tutorial on how I make a script.
1. Open up terminal
2. go to project directory // My directories usually dont have IDE project files in them, just souce and media.
3. type "vi (or any other text editor) m.sh" //This is where you start editing you script
4. type your commands you wish to execute. Ex. g++ -o MyProgram main.cpp // This is where you fill you script with commands.
5. Save
6. type "chmod +x m.sh" //You change the file to be executable
7. type "./m.sh" //This will compile your project

Now if you would like to use a makefile I think its pretty close. Just look up some tutorials about makefiles if you would like to learn about those.

##### Share on other sites
The documentation of GNU make is actually fairly thorough, so you can read through that, and/or just look for sample Makefiles of some project.

However, very few serious projects use Makefiles directly. It is more common to use higher-level tools like the autotools (autoconf/automake) or CMake. Especially CMake is fairly simple to set up, and you basically only specify a list of your source files. CMake will take care of setting up the proper Makefiles, including header dependencies and all that.

##### Share on other sites
I'd suggest something like [url="http://www.cmake.org/cmake/help/cmake_tutorial.html"]CMake[/url] instead. It makes the whole process a lot easier, and cross platform if you care for that.
In the end, it outputs a makefile or project file of your choice, that you can build in the regular way on linux, so you end up with something like:

cmake ./ && make && make install

But it also spits out Visual Studio project files if you take it over to windows.

##### Share on other sites
"I want to be able to make a makefile based command line application that will implement two passive event driven state machines with a main loop to drive them."

I think you may have slightly misunderstood what make is for. Make isn't a tool to use in your applications -- it's a build tool. The makefile describes how to compile files into other files, how to join multiple files into files and how which files depend on other files. Make then "solves" that graph building the elements as it goes.

If that's not the case, then could you elaborate a little more on what you're trying to build.

##### Share on other sites
Ok, I will elaborate step by step what I am to do in this challenge. Even though it is past my time, I would still like to understand and figure it out.

1. Create a simple makefile based command line application.
**It implements two passive event driven state machines with a main loop to drive them.
**Passive meaning neither block execution of the other for a prolonged period of time.
**Main loop should periodically call into each state machine to give each a chance to run with each state machine returning to the main loop as quickly as possible.

I left out the programming part as I already know how to do that, I just don't understand this makefile part of it. Anyone else able to elaborate on the exact meaning of this cause above is word for word.

##### Share on other sites
Makes no sense to me I'm afraid.

##### Share on other sites
Why do you keep on talking about the "[color="#1C2837"][size="2"]event driven state machines with a main loop to drive them[/size][/color]"? These are details of the program. These are not details of the build system.

make is a [b]build system[/b]. It will build your project for you. It doesn't care if it's an event-driven state machine or the embedded code for one of those automated kitty litter boxes.

##### Share on other sites
It sounds like you want a makefile containing something like this.[code]
two_machines_one_cup: machine1.o machine2.o main.o
$(CC) -o$@ \$^
[/code]That says "the executable program two_machines_one_cup out of the compiled object files machine1.o, machine2.o, and main.o ... use your implicit rules to generate those .o files from whatever you find in the current directory, like maybe main.cpp, machine1.for, and machine2.mm." The rest is dark and unspeakable magic that can be revealed to uninitiated by the evil incantation "info make".

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628300
• Total Posts
2981894

• 9
• 9
• 11
• 10
• 10