tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C

Fri Nov 04, 2016 4:48 pm

To my personal observations many libs (e.g., openVG) use make, and IIRC I also sometimes have seen installation guides which have been using makefile.
I can't remember if I have ever seen cmake, but I'm quite sure that make and makefile have been used more often than cmake AFAIK.
Anyway, IMO it's not bad to be taught how either one would work.
But I personally also am using just Geany with all my propietary (more or less static) settings for compile and build, and I also would recommend that to every beginner to C.
As the author of the MagPi C tutorial also already shows the Geany screenshots (used as an editor), it's just a small step to explain how to set the Geany compile/build preferences, and then how to use it as a both handsome and complete and powerful IDE.
- Tim

User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MagPi 47 - An Introduction to C - Page 62

Fri Nov 04, 2016 8:22 pm

Give it a go https://cmake.org/cmake-tutorial/ it's so much simpler because there's no arcane syntax requirements (like tabs).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

ejolson
Posts: 3440
Joined: Tue Mar 18, 2014 11:47 am

Re: MagPi 47 - An Introduction to C - Page 62

Fri Nov 04, 2016 11:42 pm

DougieLawson wrote:Give it a go https://cmake.org/cmake-tutorial/ it's so much simpler because there's no arcane syntax requirements (like tabs).
Thanks for the link. Replacing a makefile that looks like

Code: Select all

tutorial: tutorial.cxx
        g++ -o tutorial tutorial.cxx
with the tab-free cmake version

Code: Select all

cmake_minimum_required (VERSION 2.6)
project (Tutorial)
include(CTest)
 
# The version number.
set (Tutorial_VERSION_MAJOR 1)
set (Tutorial_VERSION_MINOR 0)
 
# does this system provide the log and exp functions?
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
 
check_function_exists (log HAVE_LOG)
check_function_exists (exp HAVE_EXP)
 
# should we use our own math functions
option(USE_MYMATH 
  "Use tutorial provided math implementation" ON)
 
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
  "${PROJECT_BINARY_DIR}/TutorialConfig.h"
  )
 
# add the binary tree to the search path for include files
# so that we will find TutorialConfig.h
include_directories ("${PROJECT_BINARY_DIR}")
 
# add the MathFunctions library?
if (USE_MYMATH)
  include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
  add_subdirectory (MathFunctions)
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)
 
# add the executable
add_executable (Tutorial tutorial.cxx)
target_link_libraries (Tutorial  ${EXTRA_LIBS})
 
# add the install targets
install (TARGETS Tutorial DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/TutorialConfig.h"        
         DESTINATION include)
 
# does the application run
add_test (TutorialRuns Tutorial 25)
 
# does the usage message work?
add_test (TutorialUsage Tutorial)
set_tests_properties (TutorialUsage
  PROPERTIES 
  PASS_REGULAR_EXPRESSION "Usage:.*number"
  )
 
 
#define a macro to simplify adding tests
macro (do_test arg result)
  add_test (TutorialComp${arg} Tutorial ${arg})
  set_tests_properties (TutorialComp${arg}
    PROPERTIES PASS_REGULAR_EXPRESSION ${result}
    )
endmacro (do_test)
 
# do a bunch of result based tests
do_test (4 "4 is 2")
do_test (9 "9 is 3")
do_test (5 "5 is 2.236")
do_test (7 "7 is 2.645")
do_test (25 "25 is 5")
do_test (-25 "-25 is 0")
do_test (0.0001 "0.0001 is 0.01")
is absolutely amazing. Though I haven't quoted the source for tutorial.cxx in this post, the program amusingly writes it's output to a file with filename given as the first argument on the command line.

On another note, in accordance with the Creative Commons (BY-SA-NC 3.0) license, the overlay feature of xournal has been used to whiteout all instances of "void main" and replace them with "int main" in MagPi Essentials: Learn to Code with C, Volume 1. The two addenda to the book have also been included.

The xournal overlay file is 17K. To view it type

Code: Select all

$ sudo apt-get xournal
$ wget https://www.raspberrypi.org/magpi-issues/Essentials_C_v1.pdf
$ wget http://fractal.math.unr.edu/~ejolson/pi/Essentials_C_Modified.xoj
$ xournal Essentials_C_Modified.xoj
While the xournal version looks good, creating an exported pdf results in a larger file in which some of the screen shots seem to have degraded. It would be great if easily-modifiable source files for this free and open source book were available.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 8:14 am

isn't that all far too complicated for beginners?
Finally it IS or SHOULD BE a tutorial designed and dedicated to beginners!
- Tim

jahboater
Posts: 4613
Joined: Wed Feb 04, 2015 6:38 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 1:24 pm

Raspbian (even Rasbian Lite) comes as standard with "make", not cmake which must be separately installed.
So I would prefer standard GNU "make" for a beginners tutorial even if its more difficult ... and its not actually hard to use IMHO, except for someone who doesn't like Python indentation either :)

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 1:28 pm

+1
;)
- Tim

User avatar
PeterO
Posts: 4954
Joined: Sun Jul 22, 2012 4:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 2:09 pm

jahboater wrote:Raspbian (even Rasbian Lite) comes as standard with "make", not cmake which must be separately installed.
So I would prefer standard GNU "make" for a beginners tutorial even if its more difficult ... and its not actually hard to use IMHO, except for someone who doesn't like Python indentation either :)
I give up with you guys... Welcome to my "foe list"....

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson


User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 7:57 pm

jahboater wrote:Raspbian (even Rasbian Lite) comes as standard with "make", not cmake which must be separately installed.
So I would prefer standard GNU "make" for a beginners tutorial even if its more difficult ... and its not actually hard to use IMHO, except for someone who doesn't like Python indentation either :)
Now build a project that has six header files and seven modules used to create three programs. The complexity of Makefiles vs CMakeLists.txt rapidly spirals out of control. My first cmake project is just about at the limit for a sane and usable Makefile. It was absolutely trivial to build the fourteen line CMakeLists.txt for that.

As a project gets bigger the cost of creating masses of arcane junk for make versus a simple text file for cmake makes it a simple choice.

Why else would cmake exist?
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 8:02 pm

Now build a project that has six header files and seven modules used to create three programs. The complexity of Makefiles vs CMakeLists.txt rapidly spirals out of control. My first cmake project is just about at the limit for a sane and usable Makefile. It was absolutely trivial to build the fourteen line CMakeLists.txt for that.
As a project gets bigger the cost of creating masses of arcane junk for make versus a simple text file for cmake makes it a simple choice.

Why else would cmake exist?
perhaps more for experts and professionals, and less for beginners and hobbyists?
- Tim

User avatar
DougieLawson
Posts: 35840
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 8:38 pm

tito-t wrote:
Now build a project that has six header files and seven modules used to create three programs. The complexity of Makefiles vs CMakeLists.txt rapidly spirals out of control. My first cmake project is just about at the limit for a sane and usable Makefile. It was absolutely trivial to build the fourteen line CMakeLists.txt for that.
As a project gets bigger the cost of creating masses of arcane junk for make versus a simple text file for cmake makes it a simple choice.

Why else would cmake exist?
perhaps more for experts and professionals, and less for beginners and hobbyists?
What aromatic materials are you smoking? Have you even looked at cmake? Because the junk you're posting on here suggests you haven't even bothered to understand why it exists, what it does and why everyone should use it in preference to plain old arcane make.

Everyone, hobbyist, professional or other should use cmake and not dismiss it as "only for experts". It's clearly made for folks who don't want to be experts at crafting Makefiles. It makes the difference between a job that takes five minutes and one that makes an hour.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 8:57 pm

for a beginner, just having passed the basic MagPi tutorial, still not even able to make a LED blink by tutorial, poll a IMU sensor by I2C, or a GPS sensor by UART, why should he have to struggle with make or cmake as we have the Geany IDE?

I'm not rejecting to be told about make, makefile, or cmake, but then use Geney IDE for the next steps. Having to deal with terminals and command lines and scripts is incredibly annoying IMO.

OTOH, a "project that has six header files and seven modules used to create three program" is not supposed to be a beginner's task, or what do you think?
So keep it simple, stupid and lead the beginner to a quick sucess by handy and powerful IDEs , i.e. . Geany.
Last edited by tito-t on Sat Nov 05, 2016 9:34 pm, edited 3 times in total.
- Tim

User avatar
PeterO
Posts: 4954
Joined: Sun Jul 22, 2012 4:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 8:59 pm

DougieLawson wrote: What aromatic materials are you smoking? Have you even looked at cmake? Because the junk you're posting on here suggests you haven't even bothered to understand why it exists,
It goes with the demands for a tutorial on flashing a led in C... So I took the time to look at doing it with Gordon's wiringPi library. Clearly those demanding "we must have tutorials" have put zero effort in to finding out anything about C programming for themselves.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sat Nov 05, 2016 9:06 pm

not a knowlege about self-sufficient and aimless C code knowledge has to be the goal but being able to program applications, i.e. one would need knowlege about
C for GPIOs
C for UART, i2c and SPI, USB
C for HATs, kits, and sets
C for graphics
C for the Pi Cam or a USB cam
C for audio
C for game programming
Getting practice by programming practical useful tools and apps, one can increase the knowlege about C via lerarning by doing.
Look how the Python tutorials are doing, that's exactly the way how a C tutorial should be designed.
Anything else can be read in 1 of the thousands C books which are already available, or already provided by websites like cplusplus.com

Of course you might wish to put another one on to this heap, Peter, I won't stop you.

But a Raspberry C tutorial for beginners to Raspberry and C (and perhaps if already having some experience using Python or Arduino C/C++) had to be hardware- and application-oriented. IMO people want to develop awesome things, and not do sort of abstract and aloof C masturbation.
- Tim

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23421
Joined: Sat Jul 30, 2011 7:41 pm

Re: MagPi 47 - An Introduction to C - Page 62

Sun Nov 06, 2016 6:28 pm

Fed up with this thread. People just getting grumpy.

So closing it.

There are thousands of C tutorials out there, some Pi related, many not. But the principles remain the same. We don't need to reinvent the wheel here. C the language and C the principles are the same whichever tutorial you use.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Return to “The MagPi”