jkilbourne
Technical User
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:
What simple thing am I missing?
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 "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?