Amiga.org

Operating System Specific Discussions => Amiga OS => Amiga OS -- Development => Topic started by: jahc on March 06, 2004, 09:27:58 AM

Title: GCC and sockets
Post by: jahc on March 06, 2004, 09:27:58 AM
My internet program compiles with no errors, but I get all these undefined references..

8.dh2:Coding/WookieChat> g++ main.cpp
/t/ccskLDZ6.o(.text+0x254c): undefined reference to `gethostbyname(unsigned char const *)'
/t/ccskLDZ6.o(.text+0x25fe): undefined reference to `socket(long, long, long)'
/t/ccskLDZ6.o(.text+0x2676): undefined reference to `setsockopt(long, long, long, void const *, long)'
/t/ccskLDZ6.o(.text+0x2690): undefined reference to `SocketBaseTags(long,...)'
/t/ccskLDZ6.o(.text+0x26e2): undefined reference to `connect(long, sockaddr const *, long)'
/t/ccskLDZ6.o(.text+0x2704): undefined reference to `IoctlSocket(long, unsigned long, char *)'
/t/ccskLDZ6.o(.text+0x271e): undefined reference to `IoctlSocket(long, unsigned long, char *)'
/t/ccskLDZ6.o(.text+0x27a4): undefined reference to `send(long, char const *, long, long)'
/t/ccskLDZ6.o(.text+0x29c0): undefined reference to `send(long, char const *, long, long)'
/t/ccskLDZ6.o(.text+0x2a52): undefined reference to `send(long, char const *, long, long)'
/t/ccskLDZ6.o(.text+0x2ae0): undefined reference to `send(long, char const *, long, long)'
/t/ccskLDZ6.o(.text+0x2b52): undefined reference to `send(long, char const *, long, long)'
/t/ccskLDZ6.o(.text+0x2bde): more undefined references to `send(long, char const *, long, long)' follow
/t/ccskLDZ6.o(.text+0x35d8): undefined reference to `recv(long, char *, long, long)'
/t/ccskLDZ6.o(.text+0x3604): undefined reference to `Errno(void)'
/t/ccskLDZ6.o(.text+0x3646): undefined reference to `shutdown(long, long)'
collect2: ld returned 1 exit status


I'm using GCC 2.95.3 and the MiamiSDK header files that came on the Amiga Developer CD 2.1..

Any ideas on how to fix? I hope I've provided enough information..

Title: Re: GCC and sockets
Post by: Kronos on March 06, 2004, 09:37:32 AM
Seems you are missing a link-library .....
Not sure wether a gcc-version is provided with Miami.

Have you tried finding an SDK for AmiTCP/Genesis ? Maybe in the 3.9NDK ?

There should also be an option to circumvent the need for an link-lib, by
useing compiler-specific #pragmas, but I have no clue how those would have to look
like for gcc-68k  :-(
Title: Re: GCC and sockets
Post by: jahc on March 07, 2004, 06:53:49 AM
I've just tried the amitcp header files and got the same result..

Listing > Ram Disk:AmiTCP-SDK-4.3/netlib

net.lib                  <   24844 ----rwed  2-12-96 23:42:56
netd.lib                 <   14948 ----rwed  2-12-96 23:42:58
netdnb.lib               <   15388 ----rwed  2-12-96 23:42:58
netnb.lib                <   25508 ----rwed  2-12-96 23:42:58
rpcdr.lib                <   37940 ----rwed  2-12-96 23:42:58
rpcr.lib                 <   37656 ----rwed  2-12-96 23:42:58
sana2.lib                <    2656 ----rwed  2-12-96 23:43:00
sana2nb.lib              <    2692 ----rwed  2-12-96 23:43:00

Are these files "link-libraries"? If so how do I use them in GCC.. I've done a "G++ --help" in shell but havent spotted anything which seems obvious.. I tried copying them to certain folders without sucess as well.

Title: Re: GCC and sockets
Post by: jahc on March 10, 2004, 04:25:45 AM
Okay RobinC has talked me through creating a link library and using it with GCC.. all works now.

If anyone else is having problems this is how it was solved:

I'm using the MiamiSDK header files. In the MiamiSDK directory is a dir called "FD". You need to turn "SOCKET_LIB.FD" into a link library. Get the latest "fd2pragma" off aminet, then type:

fd2pragma SOCKET_LIB.FD 12 TO socket.lib CLIB CLIB/SOCKET_PROTOS.H
(or wherever you keep your socket_protos.h file)
(btw, for some reason, I had to create a directory called socket.lib for this to work.. small technicality, doesnt matter!)

then:
hunk2aout socket.lib

then:
ar -rs libsocket.a obj.*

then copy the end result, which is "libsocket.a" to gg:lib/ , then you can use it in your program!

when you #include your socket headers, put them inside an extern "C" {}.. i.e.

extern "C"
{
#include
}

.. then when you compile, put "-lsocket" at the end. e.g.
g++ main.cpp -lsocket

and bobs your uncle.

I hope someone else finds this useful one day. It seems like the only newbie using this forum these days.

Title: Re: GCC and sockets
Post by: Steady on March 10, 2004, 08:28:31 AM
Hey, thanks for making that public Jahc (and to RobinC for the original help). I'm just setting up gcc and going through the fun of trying to locate what it claims are missing bits. This is probably going to come in very handy when I can use gcc properly. Consider it stolen... ;-)
Title: Re: GCC and sockets
Post by: jahc on March 11, 2004, 01:16:26 AM
I'm glad someone else found this useful. :)