Introduction and how to set up a project without an IDE

So I'm just getting into C++ and have a few questions.
But, first, I believe a (hopefully brief) introduction is in order.

I'm no stranger to programming in general, as I did poke around with BASIC and 6502 assembly language (both on the venerable Commodore 64) back in the mid-1980s.

More recently, with this ongoing 'human malware' situation cutting off my normal hobby pursuits, I decided to get back into electronics.

I attempted to duplicate a piece of obscure test equipment from the 1980s, which used a variant of the MC6800 processor. Unfortunately, not only is that particular variant (SC44125P) impossible to find today, the two processors I had available are apparently nonfunctional.

So, the hardware portion of the project is on hold while I untangle ~8K of 6800 assembly language and attempt to rewrite it in C++, to allow me to use a more modern solution, be it FPGA, Pi, or even (sigh) Arduino.

Now, on to the resources I’ve tried and am now using -

I attempted to install either of the two recommended IDEs for my platform (macOS, unfortunately), but neither is really an option.

The CodeBlocks dev group currently does not have anyone to maintain the macOS version, and the previous version, when installed, is actually missing non-trivial portions of the GUI, so that wasn’t a good option.

When I tried the other option, Apple’s Xcode, seeing it consume over 32 gigabytes (!!!) of drive space before I even opened it for the first time was enough for me to send it off to the bit bucket.

So, I’m using BBEdit for now, and found an online C++ debugger to validate my code, and also do have gcc.

Now, then, after all that - my question.

Up to now, I’ve been working on this as one big file, but I’ve come to realize it may work better if I split the project into several parts for easier analysis and rewriting, but I’m a bit fuzzy on how #include works and how to set up the project.

The 8 parts are -

One file to tie the parts together
One to contain the variable definitions (for now, these likely need to be global, but as I get a better understanding, I intend to demote as many as possible to local)
One to properly initialize all the variables (when doing initial startup or subsequent restarts)
One to contain most of the functions
One to contain the interrupt-driven function
One to contain the output function
One to contain the main executable

How do I properly format the headers of the subsidiary files and link them from whichever I choose to be the main file?
You could start with https://www.cplusplus.com/articles/Gw6AC542/



You could get CMake too https://cmake.org/
https://cmake.org/cmake/help/latest/guide/tutorial/index.html
With cmake one writes CMakeLists.txt as instructions for cmake.
When one then runs cmake, it creates a Makefile from those instruction.
Program make reads Makefile and compiles the project as necessary.

If you don't get CMake, then you should write the Makefile yourself.

You could, of course, just call GCC directly, but in larger "project" that is no fun.
32gb is not much today. I realize you may be on an older machine, and space may be a premium, but my relatively cheap rotating hard drive holds 2 terrabytes. Maybe you need to buy a bigger drive and live with it?

that said supposedly clion is ~3gb, did you look at it? I don't know if that is current size?
vs code is small, if you want to try it -- I do not like it and delegated it as 'gui for git' status.

a big question is if you want a GUI or not. It is a lot more challenging to make one without an IDE. I really, really, really dislike make. So much that I have written shell scripts/ batch files to compile projects with just straight up g++ commands. Make is like using tar before zipping a bunch of folders: a leftover from the dark ages. If you know it and can use it and remember all the magic syntax, make does work great, or if you feel like looking it up and trying to figure it out.
Last edited on
I really, really, really dislike make. So much that I have written shell scripts/ batch files to compile projects with just straight up g++ commands.
If you know it and can use it and remember all the magic syntax, make does work great, or if you feel like looking it up and trying to figure it out.

Magic syntax? Are we talking about the same tool? The main point in make is that when you update one file in thousand-file project, the recompile is done only for affected parts.

Anyway, GNU Autotools, CMake, and qmake are all tools that write a Makefile for you (in portable manner).
(Well, GNU Autotools generates GNU Build System that will write platform-specific Makefile for you.)
Magic syntax?

a simple makefile example for hello world:
https://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
says
$(ODIR)/%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ)
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

I know what the tool does, as I said, and yes, it does it well. But it does it via pure gibberish.
The tools that write one for you are great, agreed. That is really what an IDE is doing (a GUI that builds up a hidden make or similar file), esp on unix like systems. Not sure what visual does -- it used to speak cmake, but does it still?
Last edited on
That is not even the entire file "version 5":
IDIR =../include
CC=gcc
CFLAGS=-I$(IDIR)

ODIR=obj
LDIR =../lib

LIBS=-lm

_DEPS = hellomake.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = hellomake.o hellofunc.o 
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))


$(ODIR)/%.o: %.c $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)

hellomake: $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LIBS)

.PHONY: clean

clean:
	rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ 

However, that is already quite fancy. The header(s) are in separate directory and the object files are created into their dedicated directory too, rather than among the source files.
I was just highlighting the screwy syntax part... Things like a line with $@ $^ $ in the middle of it... its like perl and regex got together and had inbred offspring. I get that its a fancy one (its trying to teach you to build them, so going overboard for hello world, version 1 is sufficient).
Or to put it another way, I have an entire *book* on how to use this 'simple command line tool'. Granted, its a small book -- 168 pages -- https://www.amazon.com/dp/0937175900?tag=uuid10-20
keskiverto: Just what I needed. Thank you!

jonnin: Unfortunately I'm down to less than 100GB available on this machine and it's Flash memory integrated with the mobo (Mac mini, so yeah... :eyes roll:)
Topic archived. No new replies allowed.