Click Here
home features news forums classifieds faqs links search
6071 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
21 crawler(s) on-line.
 136 guest(s) on-line.
 1 member(s) on-line.


 amigang

You are an anonymous user.
Register Now!
 amigang:  3 mins ago
 Tpod:  29 mins ago
 pixie:  34 mins ago
 Birbo:  48 mins ago
 Hammer:  55 mins ago
 zipper:  1 hr 23 mins ago
 amigakit:  2 hrs 19 mins ago
 MarcioD:  2 hrs 42 mins ago
 kolla:  2 hrs 50 mins ago
 matthey:  2 hrs 57 mins ago

/  Forum Index
   /  Amiga Development
      /  Noob C problem
Register To Post

Goto page ( 1 | 2 Next Page )
PosterThread
Robert 
Noob C problem
Posted on 3-Mar-2018 15:41:53
#1 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

Hi folks,

I'm trying to learn some really simple C but can't seem to get past the very basics.

Trying to follow some simple tutorials, I can't get this to compile:


Quote:

struct Library *OpenLibrary();
struct IntuitionBase *IntuitionBase;

int main()
{
IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",39);
return 0;
}


The error is Quote:
undefined reference to `OpenLibrary'


I'm aware this is probably something stupid but would appreciate if anyone can point it out to me.

Cheers

Last edited by Robert on 03-Mar-2018 at 04:13 PM.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
Kronos 
Re: Noob C problem
Posted on 3-Mar-2018 15:51:24
#2 ]
Elite Member
Joined: 8-Mar-2003
Posts: 2561
From: Unknown

@Robert

You are defining a function OpenLibrary() (otherwise it would complain at compiler level), but you fail to implement it or tell the linker where to find it.

A lot can be different depending on which compiler you use, how it is invoked on which version of AOS is the target.

Try replacing that line with:

#include >proto/exec.h>

Edit: Forum doesn't like the left-hand version of ">" so turn the 1st around.....

Last edited by Kronos on 03-Mar-2018 at 03:54 PM.
Last edited by Kronos on 03-Mar-2018 at 03:52 PM.

_________________
- We don't need good ideas, we haven't run out on bad ones yet
- blame Canada

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 3-Mar-2018 16:06:03
#3 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@Kronos

Quote:

Kronos wrote:
@Robert

You are defining a function OpenLibrary() (otherwise it would complain at compiler level), but you fail to implement it or tell the linker where to find it.

A lot can be different depending on which compiler you use, how it is invoked on which version of AOS is the target.



Thanks Kronos. The compiler is GCC 4.2.4, it's invoked from shell (e.g. gcc -o test test.c) and the OS is AmigaOS4.1.

Quote:

Try replacing that line with:

#include >proto/exec.h>

Edit: Forum doesn't like the left-hand version of ">" so turn the 1st around.....


Thanks but still seeing the same error:

undefined reference to `OpenLibrary'

Last edited by Robert on 03-Mar-2018 at 04:14 PM.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
Karlos 
Re: Noob C problem
Posted on 3-Mar-2018 16:38:46
#4 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4402
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Robert

Hey up. So, I think a problem you are facing is that Libraries in OS4 work rather differently than they did in 3.x.

Depending on how your compiler is configured, you'll want to use something like declaring:

struct IntuitionBase* IntuitionBase = NULL;
struct IntuitionIFace* IIntuition = NULL;

Get the library base:

IntuitionBase = (struct IntuitionBase*)IExec->OpenLibrary(...);

and then obtain the interface for it:

IIntuition = (struct IntuitionIface*) IExec->GetInterface((Library*)IntuitionBase, "main", 1, NULL));

It's a bit more involved. Although I am sure there is some glue logic that allows the code you have written to work as-is.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Karlos 
Re: Noob C problem
Posted on 3-Mar-2018 16:44:07
#5 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4402
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

I tend to use the following template logic for C++ at least:

template<typename L, typename I>
inline bool openMainLibInterface(L*& library, I*& interface, const char* name, uint32 version)
{
if ( (library = (L*)IExec->OpenLibrary(name, version)) ) {
if ( (interface = (I*)IExec->GetInterface((Library*)library, "main", 1, NULL)) ) {
return true;
}
else {
std::fprintf(stderr, "Opened %s [%p] but failed to get main\n", name, library);
}
}
else {
std::fprintf(stderr, "Failed to open: %s\n", name);
}
return false;
}

template<typename L, typename I>
inline void closeMainLibInterface(L*& library, I*& interface)
{
if (interface) {
IExec->DropInterface((Interface*)interface);
interface = 0;
}
if (library) {
IExec->CloseLibrary((Library*)library);
library = 0;
}
}

So that I can open/close libraries and their main interfaces easily.

struct IntuitionBase* IntuitionBase = 0;
struct IntuitionIFace* IIntuition = 0;

if (openMainLibInterface(IntuitionBase, IIntuition, "intuition.library")) {
...
}

Also, I forgot how to post indentible in xoops lol.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
bison 
Re: Noob C problem
Posted on 3-Mar-2018 16:44:48
#6 ]
Elite Member
Joined: 18-Dec-2007
Posts: 2112
From: N-Space

@Robert

Actually, I think that is a linker error. If it were the compiler, it would say something like

Quote:
error: implicit declaration of function 'OpenLibrary'

You probably need to compile with something like

Quote:
gcc -o test test.c -lfoo

where 'foo' is the name of the library.

I know how to find library names on Linux, not not on AmigaOS 4.x -- perhaps someone else can add this information.

Update: or maybe not. Take a look at this:

http://wiki.amigaos.net/wiki/The_Hacking_Way:_Part_1_-_First_Steps#Myth_.231:_AmigaOS_behaves_like_UNIX

Last edited by bison on 03-Mar-2018 at 04:55 PM.

_________________
"Unix is supposed to fix that." -- Jay Miner

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 3-Mar-2018 16:51:55
#7 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@Karlos

Hey Karlos! Long time no' speak, etc. Hope you're well, sir.

Anyway, back to the issue at hand, that's helped at least as far as getting rid of the error.
Thanks.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: Noob C problem
Posted on 3-Mar-2018 16:59:02
#8 ]
Elite Member
Joined: 9-Jun-2004
Posts: 12817
From: Norway

@Robert

Quote:
Trying to follow some simple tutorials, I can't get this to compile:

Well the tutorial is wrong, maybe not so good idea to learn how to code from some one who is clueless.
Quote:
struct Library *OpenLibrary();


I not sure what your trying to do here?
It is 110% wrong.

you need includes on top file.

#include "proto/exec.h"
#include "proto/dos.h"
#include "proto/IIntuition.h"

should " should be greater or smaller but breaks.

you should compile with:

gcc source.c -o your_program_name -D__USE_INLINE__

"-D__USE_INLINE__" allows you drop "IEXEC->" from OpenLibrary, or else it is.

DOSBase = IExec->OpenLibrary("dos.library",50);

Next you need to Obtain a Interface before you call any function inside the library..
(this only AmigaOS4.1)

See the AmigaOS4.1 SDK autodocs for Exec.library
It in the SDK:Documentation/Autodocs directory.

Last edited by NutsAboutAmiga on 03-Mar-2018 at 05:10 PM.
Last edited by NutsAboutAmiga on 03-Mar-2018 at 05:08 PM.
Last edited by NutsAboutAmiga on 03-Mar-2018 at 05:02 PM.
Last edited by NutsAboutAmiga on 03-Mar-2018 at 04:59 PM.

_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 3-Mar-2018 17:03:19
#9 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@NutsAboutAmiga

Quote:

NutsAboutAmiga wrote:

Well the tutorial is wrong, maybe not so good idea to learn how code from some who is clueless.


It's from here:
http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0578.html

If anyone knows a decent resource for OS4-specific beginner tutorials, that would be appreciated.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: Noob C problem
Posted on 3-Mar-2018 17:10:20
#10 ]
Elite Member
Joined: 9-Jun-2004
Posts: 12817
From: Norway

@Robert

Have look here:

http://wiki.amigaos.net/wiki/Tutorials:Main

This one nice to start with, learn what this does.

http://wiki.amigaos.net/wiki/Programming_AmigaOS_4:_Exec_-_The_Kernel

Last edited by NutsAboutAmiga on 03-Mar-2018 at 05:13 PM.

_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: Noob C problem
Posted on 3-Mar-2018 17:25:28
#11 ]
Elite Member
Joined: 9-Jun-2004
Posts: 12817
From: Norway

@Robert



/* easy.c: a complete example of how to open an Amiga function library in
* C. In this case the function library is Intuition. Once the Intuition
* function library is open, any Intuition function can be called. This
* example uses the DisplayBeep() function of Intuition to flash the
* screen With SAS/C (Lattice), compile with lc -L easy.c
*/

/* Declare the return type of the functions we will use. */
struct Library *OpenLibrary(); /* These Exec library functions can be */
void CloseLibrary(); /* called anytime (Exec is always open). */

void DisplayBeep(); /* Before using this Intuition function, */
/* the Intuition library must be opened */



you should never declare library functions like that,
should always use the includes, as this code is old, it need to be updated.


struct IntuitionBase *IntuitionBase; /* Get storage for the library base */
/* The base name MUST be */
/* IntuitionBase */


This one should work fine, same as on AmigaOS4.


int main()
{
IntuitionBase=(struct IntuitionBase *)
OpenLibrary("intuition.library",33L);

if(IntuitionBase) /* Check to see if it actually opened. */
{ /* The Intuition library is now open so */



and then you need to open Interface, as this was not needed before AmigaOS4.


DisplayBeep(0L); /* any of its functions may be used. */


DisplayBeep(0L) wont work on RTG screen, you wont see any color change on the screen.



CloseLibrary(IntuitionBase); /* Always close a library if not */
/* in use. */



you need to close the interface after obtaining a interface.



}
else /* The library did not open so return an */
{ /* error code. The exit() function is */
exit(20); /* not part of the OS, it is part of the */
} /* compiler link library. */
}

_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 3-Mar-2018 17:39:47
#12 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@NutsAboutAmiga

Quote:

NutsAboutAmiga wrote:
@Robert

Have look here:

http://wiki.amigaos.net/wiki/Tutorials:Main

This one nice to start with, learn what this does.

http://wiki.amigaos.net/wiki/Programming_AmigaOS_4:_Exec_-_The_Kernel



Thanks very much, I'll check that out.

Last edited by Robert on 03-Mar-2018 at 05:52 PM.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
Karlos 
Re: Noob C problem
Posted on 3-Mar-2018 20:29:51
#13 ]
Elite Member
Joined: 24-Aug-2003
Posts: 4402
From: As-sassin-aaate! As-sassin-aaate! Ooh! We forgot the ammunition!

@Robert

Not bad mate. One or two minor changes since we last spoke I guess. Married, two children :D

Hope all is well with yourself.

Last edited by Karlos on 03-Mar-2018 at 08:30 PM.

_________________
Doing stupid things for fun...

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 3-Mar-2018 21:23:02
#14 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@Karlos

Quote:

Karlos wrote:
@Robert

Not bad mate. One or two minor changes since we last spoke I guess. Married, two children :D


Yes, minor changes indeed!

Belated congratulations on all counts.

Quote:
Hope all is well with yourself.


As well as could be reasonably expected for an auld geek.
Finally finding the odd half hour here and there to play with my Amigas again, which has been a pleasant distraction. Got the A1 and Peg1 up and running again.
Unfortunately the A1200 remains switched off for now as I have been unable to locate the cable that connects it to the 1084s but it still looks nice sitting there.

_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
Hypex 
Re: Noob C problem
Posted on 4-Mar-2018 15:11:28
#15 ]
Elite Member
Joined: 6-May-2007
Posts: 11204
From: Greensborough, Australia

@Robert

I don't think that would work on an actual Amiga either. As stated it's missing includes. That's makes a bad example.

 Status: Offline
Profile     Report this post  
broadblues 
Re: Noob C problem
Posted on 4-Mar-2018 20:02:38
#16 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4446
From: Portsmouth England

@Hypex

Quote:

don't think that would work on an actual Amiga either. As stated it's missing includes. That's makes a bad example.


It doesn't need any includes. All the functions have been declared, so it would build, but it would need linking against a libamiga to get the library call stubs.

It is ofcourse a pretty bad example.

@Robert

Here is how you would do it now


#define __USE_INLINE__

#include <proto/exec.h>
#include <proto/intuition.h>

struct Library *IntuitionBase;
struct IntuitionIFace *IIntuition;

int main(int argc, char *argv[])
{
if((IntuitionBase = OpenLibrary("intuition.library",0L)))
{
#if defined (__amigaos4__)
if((IIntuition = (struct IntuitionIFace *)GetInterface(IntuitionBase, "main",1,0)))
{
#endif
DisplayBeep(0L);

#if defined (__amigaos4__)
DropInterface((struct Interface *)IIntuition);
}
#endif
CloseLibrary(IntuitionBase);
}
}


Save as test.c and

Link with

gcc -o test text.c -Wall -Werror

Run it and watch your screen bar flash (possibly hear a beep depending on your Sound Prefs).

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
broadblues 
Re: Noob C problem
Posted on 4-Mar-2018 20:09:09
#17 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4446
From: Portsmouth England

@NutsAboutAmiga

Quote:

DisplayBeep(0L) wont work on RTG screen, you wont see any color change on the screen.


Except that it does. It's patched by Iprefs (I think) since quite some time, to play a sound and or flash the title bar.

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
NutsAboutAmiga 
Re: Noob C problem
Posted on 4-Mar-2018 21:00:46
#18 ]
Elite Member
Joined: 9-Jun-2004
Posts: 12817
From: Norway

@broadblues

I guess that beta or something you have?

I know nothing, not part of inner circle.

Last edited by NutsAboutAmiga on 04-Mar-2018 at 09:02 PM.
Last edited by NutsAboutAmiga on 04-Mar-2018 at 09:00 PM.

_________________
http://lifeofliveforit.blogspot.no/
Facebook::LiveForIt Software for AmigaOS

 Status: Offline
Profile     Report this post  
Robert 
Re: Noob C problem
Posted on 4-Mar-2018 22:55:02
#19 ]
Cult Member
Joined: 10-Mar-2003
Posts: 879
From: Glasgow

@broadblues (& all)

These replies are excellent, thanks.
I'm already getting a *slightly* better understanding of things.

Cheers.


_________________
Robert
--
A1XE G4, OS4.1. Peg1 G3, MOS 1.4.
Abel Soul - Check out our tunes on Spotify

 Status: Offline
Profile     Report this post  
broadblues 
Re: Noob C problem
Posted on 5-Mar-2018 0:49:06
#20 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4446
From: Portsmouth England

@NutsAboutAmiga

Quote:

I guess that beta or something you have?

I know nothing, not part of inner circle.


Hardly beta, it's been that way since 3.1 and I think even 2.04 but I don't have 2..04 to check on.

If you *don't* see flash or hear a beep, chack your sound prefs settings.

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
Goto page ( 1 | 2 Next Page )

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle