We are trying to link a .cpp main file with a C object(.o) and C++
object(.o) using xlC compiler on IBM-AIX.
Please let us know, if anyone has a solution to this problem described
below.
Test programs and various options tried :
CASE 1 :
Total 4 Files-
Names 1) com.h
2) prog5.cpp
3) prog3.c
4) main.cpp
/* File com.h declares class test_c1 */
Thanks
class test_c1{
public:
test_c1()
{
cout << "this class test";
}
/* File prog5.c declares function prog5() */Quote:};
#include <stdio.h>
#include <string.h>
int prog5()
{
strlen("abcd");
printf("prog 5 Hello World !!!\n");
return(0);
/* File main.cpp declares class test_c1 */Quote:}
#include <stdio.h>
#include <iostream.h>
#include "com.h"
extern int prog5(void);
extern void prog3();
void main(void)
{
test_c1 t2;
printf("this is a test\n");
prog5();
prog3();
/* File prog3.c declares function prog3() */Quote:}
#include <stdio.h>
#include <string.h>
#include <iostream.h>
#include "com.h"
int prog3()
{
test_c1 t1;
strlen("abcd");
printf("3 Hello World !!!\n");
return(0);
Created objects(.o files) using the following command :Quote:}
xlC -c prog3.cpp
xlC -c main.cpp
xlC -c prog5.c
Linking the objects(.o files) :
xlC main.o prog3.o prog5,o
This is the error :
ld: 0711-317 ERROR: Undefined symbol: .prog5()
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more
information.
CASE 2 :
Total 3 Files-
Names 1) extern.h
2) link.c
3) main.cpp
File extern.h declares function cool()
extern "C"{
extern void cool(char *a);
}
File link.c defines function cool()
#include <stdio.h>
void cool(char *a){
printf("called\n");
}
File main.cpp //contains main() procedure
#include <stdio.h>
#include <string.h>
#include <sys/malloc.h>
#include "extern.h"
void main(void){
char a[10];
strcpy(a, "text");
char *b = (char *)malloc(10);
cool(a);
free(b);
}
Procedures Followed -
Proc 1
To create link.o executed command
$ cc -c link.c
To create main.o executed command
$ xlC -c main.cpp
To create executable a.out executed command
$ xlC main.o link.o
Errors -(Screen Capture)
$ xlC main.o link.o
ld: 0711-317 ERROR: Undefined symbol:
kernel_heap
ld: 0711-317 ERROR: Undefined symbol: .xmalloc
ld: 0711-317 ERROR: Undefined symbol: .xmfree
ld: 0711-345 Use the -bloadmap or -bnoquiet
option to obtain more information.
Proc 2
To create link.o executed command
$ xlC -c link.c
To create main.o executed command
$ xlC -c main.cpp
To create executable a.out executed command
$ xlC main.o link.o
Errors -(Screen Capture)
$ xlC main.o link.o
ld: 0711-317 ERROR: Undefined symbol:
kernel_heap
ld: 0711-317 ERROR: Undefined symbol: .xmalloc
ld: 0711-317 ERROR: Undefined symbol: .xmfree
ld: 0711-345 Use the -bloadmap or -bnoquiet
option to obtain more information.
Proc 3
To create link.o executed command
$ xlC -+ -c link.c
To create main.o executed command
$ xlC -c main.cpp
To create executable a.out executed command
$ xlC main.o link.o
Errors -(Screen Capture)
$ xlC main.o link.o
ld: 0711-317 ERROR: Undefined symbol:
kernel_heap
ld: 0711-317 ERROR: Undefined symbol: .xmalloc
ld: 0711-317 ERROR: Undefined symbol: .cool
ld: 0711-317 ERROR: Undefined symbol: .xmfree
ld: 0711-345 Use the -bloadmap or -bnoquiet
option to obtain more information.
Sent via Deja.com http://www.deja.com/
Before you buy.