Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 11 2002
Added on Jan 11 2002
1 comment
191 views