HPGCC 2.0 and Programmer's Notepad - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: HPGCC 2.0 and Programmer's Notepad (/thread-8095.html) |
HPGCC 2.0 and Programmer's Notepad - Helix - 04-03-2017 12:19 AM I'm currently learning C. I can run small programs on my HP 50g with HPGCC 2.0 and Programmer's Notepad, as shown in this page. Compilation works fine with the "Make this .hp" tool, as long as there is only one file to compile. But if I want to create a project with a function in a second file, say myfunction in myfile.c, and with myfile.h for the header, then I get the error: "undefined reference to 'myfunction'. It seems that the "Make this .hp" tool doesn't link the files. This project works perfectly with Code::Blocks, so I suppose my code is correct. Is there a way to compile such a project with the Programmer's Notepad? RE: HPGCC 2.0 and Programmer's Notepad - brickviking - 04-04-2017 03:44 AM (04-03-2017 12:19 AM)Helix Wrote: I'm currently learning C. I'm assuming here that you've used #include "myfile.h" in your myfile.c and put the myfile.h in the same directory? Wouldn't have been the first time I'd missed it out either. This error might be turning up at the preprocessor stage, not the linker stage. (Post 59) RE: HPGCC 2.0 and Programmer's Notepad - Helix - 04-04-2017 04:44 PM (04-04-2017 03:44 AM)brickviking Wrote: I'm assuming here that you've used #include "myfile.h" in your myfile.c and put the myfile.h in the same directory? Yes, I've done that. In fact, I may have found what happens: in the Egan Ford's tutorial (that I don't follow because it is too overwhelming for a beginner like me) I read in the Makefiles section: "The Makefile in ~/hpgcc/test is a Makefile I modified from the HPGCC distribution. This Makefile is all you need if you are developing single source file binaries using only HPGCC supplied libraries." So, if I understand correctly, it is not permitted to split the source code into several files, hence the compiling error. The Windows package I use also relies on a Makefile. I don't know what a Makefile is, and I don't understand its contents, but it certainly reproduces the behavior described in the Egan Ford's page. RE: HPGCC 2.0 and Programmer's Notepad - Egan Ford - 04-05-2017 12:23 AM (04-04-2017 04:44 PM)Helix Wrote: The Windows package I use also relies on a Makefile. I don't know what a Makefile is, and I don't understand its contents, but it certainly reproduces the behavior described in the Egan Ford's page. A Makefile is the input used by the make command to create targets from sources. I'd suggest learning about Makefiles. RE: HPGCC 2.0 and Programmer's Notepad - brickviking - 04-05-2017 12:54 AM (04-04-2017 04:44 PM)Helix Wrote:(04-04-2017 03:44 AM)brickviking Wrote: I'm assuming here that you've used #include "myfile.h" in your myfile.c and put the myfile.h in the same directory? If you find the Egan Ford tutorial too overwhelming, find a more "basic" tutorial that you do understand. Compiling a C program (and the same holds for C++) goes through a few stages.
* In modern compilers, the compile phase often produces binary code directly, omitting the next stage.
There are far better explanations than this, but this'll get you at least started. And yes, you'll have to get to grips with the concepts at least. C is a rewarding language, but does take some learning, you'll also want to look up what makes a Makefile special. EDIT: Modified original post to indicate Bob's understanding. (Post 60) RE: HPGCC 2.0 and Programmer's Notepad - Helix - 04-05-2017 01:28 PM Thank you for these explanations. I did find a simple tutorial on C, and I've had no difficulties so far in understanding the first concepts of this language. But this tutorial doesn't mention Makefiles. For example, it describes only three stages to produce binary code: preprosses – compile – link. So I'm learning here there are two more stages: make and assemble. Now, my question is: why there is no Makefile with Code::Blocks? RE: HPGCC 2.0 and Programmer's Notepad - rprosperi - 04-05-2017 01:47 PM (04-05-2017 01:28 PM)Helix Wrote: Thank you for these explanations. Most modern compilers directly generate binary object files, skipping the intermediate assembler code. In some rare cases, assembler code is still used when extremely high performance, or low-level hardware access is required. When learning a new language, you can generally forget about the assembler step. Makefiles are used to automate the building (compiling, linking, etc.) of complex programs typically comprised of multiple (sometimes many) program files. The 'makefile' defines both the steps required to build the program as well as the relationships among the files (e.g. if file b must be changed, one must also compile file c again as well, because it includes file b as part of it's system). So when learning a new language with a single source file, the additional complexity of a makefile can seem like it isn't adding much value, but it's best to learn to use them from the beginning; as your skills and project complexity grow, it will be easy to extend your makefile to keep track of how to build your project, plus it's a heck of lot easier to just type "make project1" than all the tedious compiler and linker commands with precise options and syntax. |