Welcome, Guest. Please login or register.

Author Topic: Compiler  (Read 13965 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Compiler
« on: June 01, 2003, 02:45:52 AM »
@quiesce:

You seem to have quite some trouble. It's been a long time since I did any Amiga-programming with gcc, but perhaps these hints and tips will help you understand what's going wrong. Please note that this is largely quoting from memory, with lots of experience of using gcc with Linux.

First of all, using an #include does not insert the code of external functions into your program---it just tells the compiler 'Look, somewhere out there, there's a function called foo(), with parameters bar and baz. Trust me. It exists. Don't complain, just generate the proper code to *setup a call* to that function.' The job of the linker is then to look at what the compiler created, and pull out the real code of foo() from a library. If you don't supply the proper linking options to the command line, you get errors like you described. That is a tell-tale sign you forgot to link to the proper libraries.

Now libraries come in two flavours: Amiga-style .lib-format, and gcc-style lib.a-format. Note the prefix 'lib' in the gcc-name. As far as I know, the gcc linker 'ld' cannot handle the Amiga-linker libraries: their format is simply too different. (Someone please correct me if I'm wrong.) It should be possible to convert them into each other: there's bound to be a program on Aminet to do that for you. By the way, do not confuse a .lib-file with a .library-file: they are very different things!

Now then. Fist your helloworld-program. The proper compilation directive for that is:

gcc -o helloworld helloworld.c -lc

Notice that I am calling onto the C-compiler here (and not the C++-one: your program is standard C!). Also note the -lc option: this means 'Link with libc.a'. Notice that is it not -llibc.a or -llibc. If your program contains any math, you should do something like:

gcc -o calculate calculate.c -lm -lc

instructing to link with libm.a first, and then libc.a. Don't reverse the order: it can lead to problems in program execution.

You then wanted to link your program to the Reaction-lib. That doesn't work for two reasons: your program doesn't use any function from that lib so there's nothing to link, and second its file format is incorrect. It is an Amiga-style .lib-file, after all.

Finally, the compiler asked you to insert various volumes. That tells me you have not executed a little script to set all the assign's needed for the GNU-system (and thus the compiler). The compiler will not work properly until you've set them all to their proper values. I recall that there is a small package of about 50 KB called 'ade-setup' or 'gg-setup' or something similar, which contains all the necessary files to do this. It is most likely not included in a standard set of GNU gcc-executables: it is very Amiga-specific. (The Aminet directory /dev/gg has an interesting README---have you looked at it?)

Anyway, I hope that the above helps you sufficiently to get the system up and running to a point where you can compile standard C- and C++-programs; after that the next hurdle is Amiga-specific system programs. Once you can compile those, you can start thinking about Reaction. Good luck.

(Note to experienced Amiga-coders: feel free to say where I went horrendously wrong; like I said, it's been a long time :-).)
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Compiler
« Reply #1 on: June 01, 2003, 11:21:20 AM »
@quiesce:

Man, I wish Karlos or someone else helped me out here :-). I am under the impression you are trying to run before you can walk: take it one step at a time.

Once again, several issues. The '//' is a C++-style comment. gcc should not have any trouble with that when compiling in C-mode. Certainly version 2.95.x does not. Perhaps it was an addition to the compiler postdating 2.7.x.

You are correct in your understanding of the differences between a .lib- and a .library-library. In order to have gcc shut up about missing .library-functions you have three options: link to a lib which contains so-called stub code, use the compiler directive #pragma (the method used with SAS/C, AztecC and perhaps others too), or generate the necessary inline assembly statements yourself. gcc has extensive facilities for the latter. All methods do the same thing: they generate the proper code for setting up a function call to an Amiga-style run-time library. This unfortunately is somewhat different from a regular gcc-function call, hence the special treatment. If I had an Amiga myself, I could probably hack up some working code: while very arcane, it's not overly difficult.

The problem is that for the applications you wish to develop, the stub code route is difficult. You need to link to amiga.lib as well as, say, mui.lib. The former contains stub code for the basic library functions like OpenLibrary() and CloseLibrary(). The second deals with the calls specific to MUI. Unfortunately, linking fails because the gcc-linker doesn't understand the format of those libs. Since #pragma-statements are highly compiler-specific, you cannot simply 'borrow' them from the Amiga header files. Leaving you stranded with the inline assembly method of gcc... :-?

Which brings me to the final topic: I recall---a dim, hazy, nearly forgotten memory---that the SAS/C suite had a tool which performed the conversion for you. Although I don't really understand why the supplied program you mentioned fails: as far as I can remember is that linker libs *are* basically a string of 'join'ed object files. Also, ALINK was retired back in 1986, and I'm very sure the Amiga-port of the gcc-suite was developed much later. To see a program which still requires after this extinct dinosaur is surprising to say the least. Are you sure you're using the converter correctly?

I regret that's about as much I can tell you. While it is certainly possible to use gcc for Amiga-specific development (foregoing the use of ixemul), it's a bit of a pain setting it up properly and has you fiddling with internals no nere mortal should ever set eyes upon. Nevertheless, I hope you find my comments useful. Good luck!
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.
 

Offline Cymric

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 1031
    • Show all replies
Re: Compiler
« Reply #2 on: June 01, 2003, 08:17:42 PM »
@quiesce:

Karlos already did a great job of answering, and I agree with him: explicitly coding a program so it's fully multi-threaded/tasking is a very tricky job. Let the amount of programs which actually have the sort of threading you want serve as an indication. It's quite often difficult enough as it is to create a single-threaded application without there being bugs in it :-P.
Some people say that cats are sneaky, evil and cruel. True, and they have many other fine qualities as well.