Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie and Bruce Eckels CD: "undefined reference to strcopy"

Status
Not open for further replies.

jkilbourne

Technical User
Dec 15, 2001
5
US
I am using gcc on winNT, working with the CD of C programming accompanying Bruce Eckels' Thinking in C++.

I have a prgram with three files. I am not using "make"; just compile them directly. All has worked well till now.
I compile my program to an object file ok (gcc -c employ2.c), but when I try to compile it with the file with the main() method, I get the "undefined reference" error noted above. Here is my dos command line, showing the successful compilation to the .o file and the error that results both when trying to use the .o file and when recompiling from source:

C:\eckels>gcc -c employ2.c

C:\eckels>gcc -olab7 employ2.o lab7.c
employ2.o(.text+0x2a):employ2.c: undefined reference to `strcopy'
employ2.o(.text+0x40):employ2.c: undefined reference to `strcopy'
employ2.o(.text+0x56):employ2.c: undefined reference to `strcopy'
employ2.o(.text+0xfc):employ2.c: undefined reference to `strcopy'
employ2.o(.text+0x123):employ2.c: undefined reference to `strcopy'
employ2.o(.text+0x147):employ2.c: more undefined references to `strcopy' follow

C:\eckels>gcc -o lab7 employ2.c lab7.c
C:\TEMP\ccCqaaaa.o(.text+0x2a):employ2.c: undefined reference to `strcopy'
C:\TEMP\ccCqaaaa.o(.text+0x40):employ2.c: undefined reference to `strcopy'
C:\TEMP\ccCqaaaa.o(.text+0x56):employ2.c: undefined reference to `strcopy'
C:\TEMP\ccCqaaaa.o(.text+0xfc):employ2.c: undefined reference to `strcopy'
C:\TEMP\ccCqaaaa.o(.text+0x123):employ2.c: undefined reference to `strcopy'
C:\TEMP\ccCqaaaa.o(.text+0x147):employ2.c: more undefined references to `strcopy' follow

My header includes <string.h>. Here is my code, which is really eckels' code:
Code:
/* employ2.c*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include &quot;employ2.h&quot;

struct Employee* createEmployee
		(char* last, 
		char* first, 
		char* title, 
		int sal)
{
	struct Employee* p = 
		malloc(sizeof(struct Employee));
	if (p != NULL)
	{
		strcopy(p->last, last);
		strcopy(p->first, first);
		strcopy(p->title, title);
		p->salary = sal;
	}
	return p;
}

char* getLast(struct Employee* emp)
{
	return emp ? emp->last : &quot;&quot;;
}

char* getFirst(struct Employee* emp)
{
	return emp ? emp->first : &quot;&quot;;
}

char* getTitle(struct Employee* emp)
{
	return emp ? emp->title : &quot;&quot;;
}

int getSalary(struct Employee* emp)
{
	return emp->salary;
}

void setLast(struct Employee* emp, char* last)
{  
	if (emp != NULL)
	strcopy(emp->last, last);
}
void setFirst(struct Employee* emp, char* fir)
{
	if (emp != NULL)
	strcopy(emp->first, fir);
}

void setTitle(struct Employee* emp, char* title)
{
	if (emp != NULL)
	strcopy(emp->title, title);
}

void setSalary(struct Employee* emp, int sal)
{
	if (emp != NULL)
	strcopy(emp->salary, sal);
}

void printEmployee(struct Employee* emp)
{	
	putchar('{');
	
	if (emp != NULL)
		printf(&quot;%s\n%s\n%s\n%d\n&quot;, 
			emp->last,
		 	emp->first, 
			emp->title, 
			emp->salary);

	putchar('}');
}


What simple thing am I missing?
 
How about changing &quot;strcopy&quot; to &quot;strcpy&quot;.:) Ankan.

Please do correct me if I am wrong. s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top