[Dev-C++] newbie with 'undefined reference to strcopy' only on linking files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: John K. <jki...@po...> - 2001-12-30 03:29:34
|
I am using gcc on winNT, working with the CD of C programming
accompanying Bruce Eckels' Thinking in C++.
I have a program with three files. I am not using "make"; I 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 link 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 everyting 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:
/* employ2.c*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "employ2.h"
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 : "";
}
char* getFirst(struct Employee* emp)
{
return emp ? emp->first : "";
}
char* getTitle(struct Employee* emp)
{
return emp ? emp->title : "";
}
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("%s\n%s\n%s\n%d\n",
emp->last,
emp->first,
emp->title,
emp->salary);
putchar('}');
}
What simple thing am I missing?
|