Linker errors with static libs

Hi

I’m using a make file with qcc for compiling and linking in two steps.
Many source files, many obj files.
Using math and socket functions.
My problem is: as long as I don’t use -static for qcc (and add -lm and
-lsocket), everything’s fine. But since I don’t want shared libraries,
the moment I use -static to qcc, the linker(ld) starts to complain about
the math and socket calls.

Another related dumb question… the Library Reference says the
libraries are ‘libc’, ‘libm’ and ‘libsocket’ for some of the calls, but
I can’t seem to find these files on my machine!!

Thanks in advance…

Santosh Patil <sans@ieee.org> wrote in news:3C5EE9D9.6A578F5C@ieee.org:

I’m using a make file with qcc for compiling and linking in two steps.
Many source files, many obj files.
Using math and socket functions.
My problem is: as long as I don’t use -static for qcc (and add -lm and
-lsocket), everything’s fine. But since I don’t want shared libraries,
the moment I use -static to qcc, the linker(ld) starts to complain about
the math and socket calls.

Did you use the -Bstatic option, and include the path to the static libs on
the command line? What was your command line to do the linking? What
where the linker errors?

Another related dumb question… the Library Reference says the
libraries are ‘libc’, ‘libm’ and ‘libsocket’ for some of the calls, but
I can’t seem to find these files on my machine!!

Take a look under /lib


Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Replacing -static with -Bstatic seems to work (as you suggested). Don’t know
why.
I’ve attached the commands that doesn’t work.
These are the options I explicitly specified in the makefile for qcc:
-o CheckerFunction -N128K -v -lm -lsocket -static -L /lib -L .
The rest were inserted by it.

qcc -o CheckerFunction -N128K -v -lm -lsocket -static -L /lib
-L . cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o cfVIMSource.o
cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o
/usr/ntox86/bin/ld -dn -Bstatic -b elf32-i386 --dynamic-linker
/usr/lib/ldqnx.so.2 /x86/lib/crt1.o /x86/lib/crti.o /x86/lib/crtbegin.o -lm
-lsocket -L/lib -L. cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o
cfVIMSource.o cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o -o CheckerFunction -Y/x86/lib:/x86/usr/lib
-L/usr/lib/gcc-lib/ntox86/2.95.2 -L/usr/ntox86/lib
/usr/lib/gcc-lib/ntox86/2.95.2/libgcc.a -lc -dn -Bstatic -lc
/usr/lib/gcc-lib/ntox86/2.95.2/libgcc.a /x86/lib/crtend.o /x86/lib/crtn.o
cfNETSource.o: In function fnNETCloseSocket': /home/atocur/Source/cfNETSource.c:190: undefined reference to getprotobyname’
/home/atocur/Source/cfNETSource.c:193: undefined reference to setsockopt' /home/atocur/Source/cfNETSource.c:305: undefined reference to gethostbyaddr’
/home/atocur/Source/cfNETSource.c:332: undefined reference to socket' /home/atocur/Source/cfNETSource.c:340: undefined reference to connect’
/home/atocur/Source/cfNETSource.c:420: undefined reference to recv' /home/atocur/Source/cfNETSource.c:456: undefined reference to recv’
/home/atocur/Source/cfNETSource.c:498: undefined reference to send' cfSchema.o: In function fnDECGetNeighbor’:
/home/atocur/Source/cfSchema.c:1164: undefined reference to modf' cfDECWayside.o: In function fnDECDecodeFireStatus’:
/home/atocur/Source/cfDECWayside.c:583: undefined reference to pow' cfIBUtilities.o: In function Trace’:
/home/atocur/Source/cfIBUtilities.c:246: undefined reference to socket' /home/atocur/Source/cfIBUtilities.c:253: undefined reference to connect’
cc: /usr/ntox86/bin/ld error 1
cc: unlinking CheckerFunction
cc: unlinking CheckerFunction
make: *** [RELEASE1] Error 1


Thanks
Santosh

Adam Mallory wrote:

Santosh Patil <> sans@ieee.org> > wrote in news:> 3C5EE9D9.6A578F5C@ieee.org> :

I’m using a make file with qcc for compiling and linking in two steps.
Many source files, many obj files.
Using math and socket functions.
My problem is: as long as I don’t use -static for qcc (and add -lm and
-lsocket), everything’s fine. But since I don’t want shared libraries,
the moment I use -static to qcc, the linker(ld) starts to complain about
the math and socket calls.

Did you use the -Bstatic option, and include the path to the static libs on
the command line? What was your command line to do the linking? What
where the linker errors?

Another related dumb question… the Library Reference says the
libraries are ‘libc’, ‘libm’ and ‘libsocket’ for some of the calls, but
I can’t seem to find these files on my machine!!

Take a look under /lib


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

Santosh Patil <sans@ieee.org> wrote:

Replacing -static with -Bstatic seems to work (as you suggested). Don’t know
why.
I’ve attached the commands that doesn’t work.

I think you see those errors because there is no static socket lib.

Regards,

Marcin

These are the options I explicitly specified in the makefile for qcc:
-o CheckerFunction -N128K -v -lm -lsocket -static -L /lib -L .
The rest were inserted by it.

qcc -o CheckerFunction -N128K -v -lm -lsocket -static -L /lib
-L . cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o cfVIMSource.o
cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o
/usr/ntox86/bin/ld -dn -Bstatic -b elf32-i386 --dynamic-linker
/usr/lib/ldqnx.so.2 /x86/lib/crt1.o /x86/lib/crti.o /x86/lib/crtbegin.o -lm
-lsocket -L/lib -L. cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o
cfVIMSource.o cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o -o CheckerFunction -Y/x86/lib:/x86/usr/lib
-L/usr/lib/gcc-lib/ntox86/2.95.2 -L/usr/ntox86/lib
/usr/lib/gcc-lib/ntox86/2.95.2/libgcc.a -lc -dn -Bstatic -lc
/usr/lib/gcc-lib/ntox86/2.95.2/libgcc.a /x86/lib/crtend.o /x86/lib/crtn.o
cfNETSource.o: In function fnNETCloseSocket': /home/atocur/Source/cfNETSource.c:190: undefined reference to getprotobyname’
/home/atocur/Source/cfNETSource.c:193: undefined reference to setsockopt' /home/atocur/Source/cfNETSource.c:305: undefined reference to gethostbyaddr’
/home/atocur/Source/cfNETSource.c:332: undefined reference to socket' /home/atocur/Source/cfNETSource.c:340: undefined reference to connect’
/home/atocur/Source/cfNETSource.c:420: undefined reference to recv' /home/atocur/Source/cfNETSource.c:456: undefined reference to recv’
/home/atocur/Source/cfNETSource.c:498: undefined reference to send' cfSchema.o: In function fnDECGetNeighbor’:
/home/atocur/Source/cfSchema.c:1164: undefined reference to modf' cfDECWayside.o: In function fnDECDecodeFireStatus’:
/home/atocur/Source/cfDECWayside.c:583: undefined reference to pow' cfIBUtilities.o: In function Trace’:
/home/atocur/Source/cfIBUtilities.c:246: undefined reference to socket' /home/atocur/Source/cfIBUtilities.c:253: undefined reference to connect’
cc: /usr/ntox86/bin/ld error 1
cc: unlinking CheckerFunction
cc: unlinking CheckerFunction
make: *** [RELEASE1] Error 1



Thanks
Santosh

Adam Mallory wrote:

Santosh Patil <> sans@ieee.org> > wrote in news:> 3C5EE9D9.6A578F5C@ieee.org> :

I’m using a make file with qcc for compiling and linking in two steps.
Many source files, many obj files.
Using math and socket functions.
My problem is: as long as I don’t use -static for qcc (and add -lm and
-lsocket), everything’s fine. But since I don’t want shared libraries,
the moment I use -static to qcc, the linker(ld) starts to complain about
the math and socket calls.

Did you use the -Bstatic option, and include the path to the static libs on
the command line? What was your command line to do the linking? What
where the linker errors?

Another related dumb question… the Library Reference says the
libraries are ‘libc’, ‘libm’ and ‘libsocket’ for some of the calls, but
I can’t seem to find these files on my machine!!

Take a look under /lib


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

Tools Mail Account <tools@qnx.com> wrote in
news:a3n9i0$3l7$1@nntp.qnx.com:

Santosh Patil <> sans@ieee.org> > wrote:
Replacing -static with -Bstatic seems to work (as you suggested).
Don’t know why. I’ve attached the commands that doesn’t work.

I think you see those errors because there is no static socket lib.

Look under /lib, there should be a libsocket.a, and a libsocketS.a (shared
static lib).


\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

Santosh Patil <sans@ieee.org> wrote in news:3C5F15DB.30221E97@ieee.org:

Replacing -static with -Bstatic seems to work (as you suggested). Don’t
know why.

It indicated to link using static libs, which from looking at the output (I
could be blind :slight_smile: ), I don’t see where you’re linking against the static
libs.

\

Cheers,
Adam

QNX Software Systems Ltd.
[ amallory@qnx.com ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <pschon@baste.magibox.net>

I do have these options:
-lm -lsocket -static

Isn’t that supposed to pick up the correct static libs? Or do I have to specify
the libs explicitly (like /lib/libsocket.a)?

Adam Mallory wrote:

Santosh Patil <> sans@ieee.org> > wrote in news:> 3C5F15DB.30221E97@ieee.org> :

Replacing -static with -Bstatic seems to work (as you suggested). Don’t
know why.

It indicated to link using static libs, which from looking at the output (I
could be blind > :slight_smile: > ), I don’t see where you’re linking against the static
libs.


Cheers,
Adam

QNX Software Systems Ltd.
[ > amallory@qnx.com > ]

With a PC, I always felt limited by the software available.
On Unix, I am limited only by my knowledge.
–Peter J. Schoenster <> pschon@baste.magibox.net

qcc -o CheckerFunction -N128K -v -lm -lsocket -static -L /lib
-L . cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o cfVIMSource.o
cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o

You’re problem is that you are passing the libraries to the linker before
the object files that need them. GNU ld is a one pass linker - it
looks at an object, figures out the undefined references and then moves
on, not remembering the other symbols. So by the time your objects that
require the libs are processed, the libs have been processed already and
nothing was noted to require them.

Put the -lsocket -lm after your objects, and all should be well.


cburgess@qnx.com

Thanks Colin!
It works now after a long vacation :wink:

Colin Burgess wrote:

qcc -o CheckerFunction -N128K -v -lm -lsocket -static -L /lib
-L . cfNETSource.o cfGlobalData.o cfLOGSource.o cfSelfTest.o cfVIMSource.o
cfINIReadInitData.o cfINIReadFile.o cfDVConstraints.o cfSchema.o
cfSConstraints.o cfVIMCallcon.o cfDECWayside.o cfDECLoco.o cfIBSource.o
cfDECHMI.o cfIBUtilities.o

You’re problem is that you are passing the libraries to the linker before
the object files that need them. GNU ld is a one pass linker - it
looks at an object, figures out the undefined references and then moves
on, not remembering the other symbols. So by the time your objects that
require the libs are processed, the libs have been processed already and
nothing was noted to require them.

Put the -lsocket -lm after your objects, and all should be well.


cburgess@qnx.com