简体   繁体   中英

Error: Undefined first referenced symbol in file

I get this error and I'm not sure how to fix it. The request constructor takes a string type, I don't think I implemented properly in my request.h file. Error:

Undefined           first referenced
 symbol                 in file
Request::Request(char *, int, int)  threadtest.o
ld: fatal: Symbol referencing errors. No output written to nachos

code:

class Request
{
 public:
  //constructor intializes request type                                                              

  Request(char *u, int rqtID, int rqtrID);
  char *url;
  int requestID;
  int requesterID;


};

request.cc file where constructor is defined

#include "request.h"

    Request :: Request(char *urll, int requestIDD, int requesterIDD )
    {
      url = *urll
      requestID = requestIDD;
      requesterID = requesterIDD;

    }

Lets try to understand the error first.

ld: fatal: Symbol referencing errors. No output written to nachos

This means it is a linking issue. Linker is unable to find definitions for some symbols.

Undefined first referenced symbol in file Request::Request(char *, int, int) threadtest.o

Important information here is - Request::Request(char *, int, int) and threadtest.o . So, you have a source file name threadtest.cpp where you are instantiating Request object. Understand that inclusion of a header ( probably Request.h in threadtest.cpp ) helps compiler to find the declarations. Linker tries to find definitions of symbols from all object files and forms an executable.

So, possibly you are not compiling Request.cpp or forgot to link Request.o .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM