linking libxml.a problem

I can’t seem to link the following program:

#include <stdio.h>
extern “C” {
#include <xmlnode.h>
#include <xmltree.h>
}

int main( void ) {
xml_treelist_t *tree = XML_TreeListInit();
}

I use the following command to compile & link:

qcc -static -lxml -o xml1 xml1.cc

This is the error that results:

xml1.o: In function main': xml1.o(.text+0x7): undefined reference to XML_TreeListInit’
cc: /usr/ntox86/bin/ld error 1

After compiling to produce just an object file, an objdump -x
produces the following:

xml1.o: file format elf32-i386
xml1.o
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000016 00000000 00000000 00000034 22
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000004c 2
2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000004c 22
ALLOC
3 .note 00000014 00000000 00000000 0000004c 2
0
CONTENTS, READONLY
4 .eh_frame 0000002c 00000000 00000000 00000060 22
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000026 00000000 00000000 0000008c 2
0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l df ABS 00000000 xml1.cc
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l .text 00000000 gcc2_compiled.
00000000 l d .eh_frame 00000000
00000000 l .eh_frame 00000000 FRAME_BEGIN
00000000 l d .note 00000000
00000000 l d .comment 00000000
00000000 g F .text 00000016 main
00000000 UND 00000000 XML_TreeListInit


RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000007 R_386_PC32 XML_TreeListInit


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET TYPE VALUE
0000001c R_386_32 .text


The function XML_TreeListInit is listed as undefined as expected.
An abbreviated objdump -x of /usr/lib/libxml.a reports:

0000019c g F .text 00000014 XML_TreeListInit

Despite what appears to be the target function I get the same undefined
reference whether I specify “-lxml” or not.

Can anyone tell me what’s missing?

TIA

Harry Qualls,
Tree-D, Inc.

I believe we’re seeing a linkage problem with C++ here. I looked at the xml
headers and we don’t have extern “C” linkage defined in them. So the linker
is looking for name mangled C++ stuff and not finding it. Just as an
experiment, (assuming you don’t mind mangling your system headers :wink: try
putting something like

#ifdef __cplusplus
extern “C” {
#endif

near the beginning of these headers (right before any function prototypes or
global variables) and

#ifdef __cplusplus
}
#endif

at the end.

cheers,

Kris

“Harry Qualls” <hfq@tree-d.com> wrote in message
news:aaucde$7pt$1@inn.qnx.com

I can’t seem to link the following program:

#include <stdio.h
extern “C” {
#include <xmlnode.h
#include <xmltree.h
}

int main( void ) {
xml_treelist_t *tree = XML_TreeListInit();
}

I use the following command to compile & link:

qcc -static -lxml -o xml1 xml1.cc

This is the error that results:

xml1.o: In function main': xml1.o(.text+0x7): undefined reference to XML_TreeListInit’
cc: /usr/ntox86/bin/ld error 1

After compiling to produce just an object file, an objdump -x
produces the following:

xml1.o: file format elf32-i386
xml1.o
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000016 00000000 00000000 00000034 22
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000004c 2
2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000004c 22
ALLOC
3 .note 00000014 00000000 00000000 0000004c 2
0
CONTENTS, READONLY
4 .eh_frame 0000002c 00000000 00000000 00000060 22
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000026 00000000 00000000 0000008c 2
0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l df ABS 00000000 xml1.cc
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l .text 00000000 gcc2_compiled.
00000000 l d .eh_frame 00000000
00000000 l .eh_frame 00000000 FRAME_BEGIN
00000000 l d .note 00000000
00000000 l d .comment 00000000
00000000 g F .text 00000016 main
00000000 UND 00000000 XML_TreeListInit


RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000007 R_386_PC32 XML_TreeListInit


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET TYPE VALUE
0000001c R_386_32 .text


The function XML_TreeListInit is listed as undefined as expected.
An abbreviated objdump -x of /usr/lib/libxml.a reports:

0000019c g F .text 00000014 XML_TreeListInit

Despite what appears to be the target function I get the same undefined
reference whether I specify “-lxml” or not.

Can anyone tell me what’s missing?

TIA

Harry Qualls,
Tree-D, Inc.

\

“Harry Qualls” <hfq@tree-d.com> wrote in message
news:aaucde$7pt$1@inn.qnx.com

I can’t seem to link the following program:

#include <stdio.h
extern “C” {
#include <xmlnode.h
#include <xmltree.h
}

int main( void ) {
xml_treelist_t *tree = XML_TreeListInit();
}

I use the following command to compile & link:

qcc -static -lxml -o xml1 xml1.cc

This is the error that results:

xml1.o: In function main': xml1.o(.text+0x7): undefined reference to XML_TreeListInit’
cc: /usr/ntox86/bin/ld error 1

After compiling to produce just an object file, an objdump -x
produces the following:

xml1.o: file format elf32-i386
xml1.o
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000016 00000000 00000000 00000034 22
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000004c 2
2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000004c 22
ALLOC
3 .note 00000014 00000000 00000000 0000004c 2
0
CONTENTS, READONLY
4 .eh_frame 0000002c 00000000 00000000 00000060 22
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000026 00000000 00000000 0000008c 2
0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l df ABS 00000000 xml1.cc
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l .text 00000000 gcc2_compiled.
00000000 l d .eh_frame 00000000
00000000 l .eh_frame 00000000 FRAME_BEGIN
00000000 l d .note 00000000
00000000 l d .comment 00000000
00000000 g F .text 00000016 main
00000000 UND 00000000 XML_TreeListInit


RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000007 R_386_PC32 XML_TreeListInit


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET TYPE VALUE
0000001c R_386_32 .text


The function XML_TreeListInit is listed as undefined as expected.
An abbreviated objdump -x of /usr/lib/libxml.a reports:

0000019c g F .text 00000014 XML_TreeListInit

Despite what appears to be the target function I get the same undefined
reference whether I specify “-lxml” or not.

Can anyone tell me what’s missing?

TIA

Harry Qualls,
Tree-D, Inc.


\

In case you haven’t found an answer yet…

Try :
QCC -static -o xml1 xml1.cc -lxml -ltexpat

I believe the libraries need to come after all objects or sources, in order
that the linker knows which objects to include.
Also libxml.a has a dependancy on libtexpat.a, so that needs to go there
too.
If you’re compiling C++, you need to make sure that you surround the headers
with extern “C” {…}. I see you already have this, but I include it here
for the benefit of posterity and our children’s children.

Cheers,
Richard

Yup, xmlnode.h and xmltree.h neither one have #extern “C” declarations
(xmlparse.h and xmltok.h do). I added these to the latter, removed the
extern “C” from my proto and recompiled and linked successfully using:

qcc -static -o xml1 xml1.cc -l xml -l texpat

Thanks

“Kris Warkentin” <kewarken@qnx.com> wrote in message
news:ab636s$dsd$1@nntp.qnx.com

I believe we’re seeing a linkage problem with C++ here. I looked at the
xml
headers and we don’t have extern “C” linkage defined in them. So the
linker
is looking for name mangled C++ stuff and not finding it. Just as an
experiment, (assuming you don’t mind mangling your system headers > :wink: > try
putting something like

#ifdef __cplusplus
extern “C” {
#endif

near the beginning of these headers (right before any function prototypes
or
global variables) and

#ifdef __cplusplus
}
#endif

at the end.

cheers,

Kris

“Harry Qualls” <> hfq@tree-d.com> > wrote in message
news:aaucde$7pt$> 1@inn.qnx.com> …
I can’t seem to link the following program:

#include <stdio.h
extern “C” {
#include <xmlnode.h
#include <xmltree.h
}

int main( void ) {
xml_treelist_t *tree = XML_TreeListInit();
}

I use the following command to compile & link:

qcc -static -lxml -o xml1 xml1.cc

This is the error that results:

xml1.o: In function main': xml1.o(.text+0x7): undefined reference to XML_TreeListInit’
cc: /usr/ntox86/bin/ld error 1

After compiling to produce just an object file, an objdump -x
produces the following:

xml1.o: file format elf32-i386
xml1.o
architecture: i386, flags 0x00000011:
HAS_RELOC, HAS_SYMS
start address 0x00000000

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00000016 00000000 00000000 00000034 22
CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE
1 .data 00000000 00000000 00000000 0000004c 2
2
CONTENTS, ALLOC, LOAD, DATA
2 .bss 00000000 00000000 00000000 0000004c 22
ALLOC
3 .note 00000014 00000000 00000000 0000004c 2
0
CONTENTS, READONLY
4 .eh_frame 0000002c 00000000 00000000 00000060 22
CONTENTS, ALLOC, LOAD, RELOC, DATA
5 .comment 00000026 00000000 00000000 0000008c 2
0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l df ABS 00000000 xml1.cc
00000000 l d .text 00000000
00000000 l d .data 00000000
00000000 l d .bss 00000000
00000000 l .text 00000000 gcc2_compiled.
00000000 l d .eh_frame 00000000
00000000 l .eh_frame 00000000 FRAME_BEGIN
00000000 l d .note 00000000
00000000 l d .comment 00000000
00000000 g F .text 00000016 main
00000000 UND 00000000 XML_TreeListInit


RELOCATION RECORDS FOR [.text]:
OFFSET TYPE VALUE
00000007 R_386_PC32 XML_TreeListInit


RELOCATION RECORDS FOR [.eh_frame]:
OFFSET TYPE VALUE
0000001c R_386_32 .text


The function XML_TreeListInit is listed as undefined as expected.
An abbreviated objdump -x of /usr/lib/libxml.a reports:

0000019c g F .text 00000014 XML_TreeListInit

Despite what appears to be the target function I get the same undefined
reference whether I specify “-lxml” or not.

Can anyone tell me what’s missing?

TIA

Harry Qualls,
Tree-D, Inc.



\