Undefined symbol error
807578Jan 11 2002 — edited Jan 14 2002
Hi,
I am new to the forum. Thanks in advance for any comments. I am using cc and CC(Sun WorkShop 6)compilers under SUN solaris 5.7.
Here is what I have done. I have a libprint.o compiled by CC (source is libprint.cpp).
The command is:
CC -c libprint.cpp .
When I use:
cc -o client client.c libprint.o
I got error message:
/*************************/
Undefined first referenced
symbol in file
printstring client.o
ld: fatal: Symbol referencing errors. No output written to client
/*************************/
What I have done wrong? How to link C .o file and C++ .o file to an executable file?
Here are the source files:
1. libprint.h
/* file libprint.h */
void printstring(char* str);
/* end of file libprint.h */
2. client.c
/* client.c */
#include "libprint.h"
#include "stdio.h"
void main()
{
printf("\nIn Main!\n");
printstring("In Main!\n");
}
/* end of client.c */
3. libprint.cpp
/* file libprint.cpp */
#include "stdio.h"
void printstring(char* str)
{
printf("String: %s\n", str);
}
/* end of file libprint.cpp */
Andy Zou
zou.xiaoquan@mayo.edu