-1

I am working on a school project with Nachos and I am receiving some strange error. You can see my code here: just the c file, lemme know if you need more

The output from the console looks like this:

../gnu/gcc -G 0 -c -I../userprog -I../threads -I../machine -c threadtest.c
../gnu/ld -T newscript -N start.o threadtest.o -o threadtest.coff
threadtest.o: In function `CreateClerk':
threadtest.c:804: undefined reference to `memcpy'
threadtest.o: In function `ApplicationClerkNoCustomerAtRegister':
threadtest.c:902: undefined reference to `memcpy'
threadtest.c:902: undefined reference to `memcpy'
threadtest.c:902: undefined reference to `memcpy'
threadtest.o: In function `PictureClerkNoCustomerAtRegister':
threadtest.c:954: undefined reference to `memcpy'
threadtest.o:threadtest.c:954: more undefined references to `memcpy' follow
gmake: *** [threadtest] Error 1

In my entire Nachos project folder there isn't one single call to 'memcpy' (I did a find in files search with Brackets).

Here is line 804+:

struct Clerk CreateClerk(char* _name, int _number, struct PassportOffice* _theOffice, struct Line* theLine) {
    struct Clerk theClerk;
    theClerk.name = _name;
    theClerk.number = _number;
    theClerk.theOffice = _theOffice;
    theClerk.myLine = theLine;
    LineSetClerk(theClerk.myLine,&theClerk);
    theClerk.dataLock = CreateLock("dataLock",8);
    theClerk.myBribeCV = CreateCV("myBribeCV",9);
    theClerk.breakCV = CreateCV("breakCV",7);
    theClerk.breakLock = CreateLock("breakLock",9);
    theClerk.walkUpCV = CreateCV("walkUpCV",8);
    return theClerk;
}
Jonathan Allen Grant
  • 3,408
  • 6
  • 30
  • 53
  • Would seeing my Makefile help? – Jonathan Allen Grant Oct 16 '15 at 02:21
  • 1
    Why did you comment out your includes? – user2357112 Oct 16 '15 at 02:21
  • For the project specifications. I am only allowed to include "syscall.h" which I can provide for you, but it doesn't seem like it has anything to do with the problem. Threadtest.c is meant to run like a user program, and syscall.h are the kernel syscalls I can use. – Jonathan Allen Grant Oct 16 '15 at 02:22
  • Is there a particular reason you're calling the linker directly instead of through gcc? – dbush Oct 16 '15 at 02:25
  • I'm not sure what code you are referring to. It is probably something that was provided as part of the assignment. I'm running this through Nachos (https://en.wikipedia.org/wiki/Not_Another_Completely_Heuristic_Operating_System) – Jonathan Allen Grant Oct 16 '15 at 02:27
  • Your code needs to be in your question here. Expecting us to leave this site to look at the code to figure out what you're asking is unreasonable and unacceptable. Please include the **relevant** portions of your code here in the question itself. This is clearly explained in the [help]. Placing the important content elsewhere means that the question becomes meaningless if that off-site content is unavailable in the future. Questions (and answers) should be self contained, with links to external material only used for additional references. – Ken White Oct 16 '15 at 02:34
  • Does `syscall.h` have a reference to `memcpy()` somewhere? – John Perry Oct 16 '15 at 02:36
  • @JohnPerry no it does not – Jonathan Allen Grant Oct 16 '15 at 02:37
  • @KenWhite You are right, but I don't think there's enough room to post all the relevant code. I'll give it a shot. – Jonathan Allen Grant Oct 16 '15 at 02:37
  • *Relevant code* means precisely that - reduce the code to create a MCVE that demonstrates the problem. – Ken White Oct 16 '15 at 02:40
  • Could it be because your compiler has a bug? I don't know how nachos works, but perhaps it has a custom gcc that inserts its own memcpy in order to copy the struct in line 804, and someone forgot to include it somewhere along the line? (and you can't) For instance, if you changed the way it worked by passing an argument by reference or pointer, and had `CreateClerk()` return void, maybe it would go away. Have you tried that, or does the assignment forbid it? – John Perry Oct 16 '15 at 02:45
  • Did that, still get the errors – Jonathan Allen Grant Oct 16 '15 at 02:50
  • OK, sorry I was no help. SO is complaining about extended discussion, so I'll deleted most of my comments. – John Perry Oct 16 '15 at 02:54
  • `-ffreestanding`, if you are not allowed libc? – Marc Glisse Oct 16 '15 at 07:14

1 Answers1

2

You should use gcc to link, not ld.

When you link via gcc it supplies the system libraries to ld . If you link via ld you have to specify all that yourself, and a pile of other things.

M.M
  • 138,810
  • 21
  • 208
  • 365