Live data from Hacker News

A Simple Makefile for Medium-Sized C/C++ Projects

spin.atomicobject.com

11–20 of 120 posts

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#13
post #7
post #6

Earlier quoted context omitted.

Would be nice if you could give an example, not just "use that".

Especially since scons and cmake are in no way easy to learn, imho.

Still hell of a lot simpler than hand-writing Makefiles though. For both small and large projects.

I mean, a "hello world" CMakeLists.txt can be literally just this:

    add_executable(hello hello.c)
And it's cross-platform, can generate Visual Studio/Xcode/... projects, etc.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#15
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

Sadly you're bitten by the biggest misfeature in Make - You must use TABs not spaces.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#16
It always annoys me that we don't have better solutions for building C and C++ projects by now. My own take on the generic drop-in makefile[1] has over 1000 stars on github, which says pretty loudly to me that this is a common pain point for many people. Alas I haven't had a brilliant idea for a solution (yet).

[1]: https://github.com/mbcrawfo/GenericMakefile

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#17
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

Your editor probably automatically converted tabs into spaces. And just like that, the Makefile stops working.

Which proves the point: Makefiles are at a point in life where they should be exclusively automatically generated.

The only exception are throwaway projects where you and only you use it.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#18
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

Make unfortunately depends on hard-tabs for the recipes. Your editor probably switched it to spaces.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#19
post #6

Just use cmake or scons. In 2016, you should not hand write a single makefile ! A simple cmake/sconcs build file will be as simple as the one shown (or even simpler !) and it will definitively will be easier to integrate external dependencies if you have to.

Would be nice if you could give an example, not just "use that".

https://cmake.org/examples/

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#20
post #6

Just use cmake or scons. In 2016, you should not hand write a single makefile ! A simple cmake/sconcs build file will be as simple as the one shown (or even simpler !) and it will definitively will be easier to integrate external dependencies if you have to.

Would be nice if you could give an example, not just "use that".

$ ls src

demo.cxx demo_b.cxx CMakeLists.txt

$ cat src/CMakeLists.txt

cmake_minimum_required (VERSION 2.8.11)

project (HELLO)

add_executable (helloDemo demo.cxx demo_b.cxx)

$ mkdir bin

$ cd bin

$ cmake ../src

SNIP

$ make

$ ./helloDemo

Post reply on HN