HPGCC 2.0 and Programmer's Notepad
|
04-03-2017, 12:19 AM
(This post was last modified: 04-03-2017 12:24 AM by Helix.)
Post: #1
|
|||
|
|||
HPGCC 2.0 and Programmer's Notepad
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? Jean-Charles |
|||
04-04-2017, 03:44 AM
Post: #2
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
(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) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
04-04-2017, 04:44 PM
Post: #3
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
(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. Jean-Charles |
|||
04-05-2017, 12:23 AM
Post: #4
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
(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. |
|||
04-05-2017, 12:54 AM
(This post was last modified: 04-06-2017 08:56 PM by brickviking.)
Post: #5
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
(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) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
04-05-2017, 01:28 PM
Post: #6
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
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? Jean-Charles |
|||
04-05-2017, 01:47 PM
Post: #7
|
|||
|
|||
RE: HPGCC 2.0 and Programmer's Notepad
(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. --Bob Prosperi |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: