OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 5:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 9:24 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
Hello, C++ is getting an undefined frequency error. I am attaching the C++ Source Codes and the Screenshot of the Error.

port.cpp soucres code:
Code:
#include "port.h"

Port::~Port()
{
}



Port8Bit::Port8Bit(uint16_t portnumber)
: Port(portnumber)
{
}

Port8Bit::~Port8Bit()
{
}

void Port8Bit::Write(uint8_t data)
{
   __asm__ volatile("outb %0, %1" : : "a" (data), "Nd" (portnumber));
}

uint8_t Port8Bit::Read()
{
     uint8_t result;
    __asm__ volatile("inb %1, %0" : "=a" (result) : "Nd" (portnumber));
    return result;
}




Port8BitSlow::Port8BitSlow(uint16_t portnumber)
: Port8Bit(portnumber)
{
}

Port8BitSlow::~Port8BitSlow()
{
}

void Port8BitSlow::Write(uint8_t data)
{
   __asm__ volatile("outb %0, %1\njmp 1f\n1: jmp 1f\n1:" : : "a" (data), "Nd" (portnumber));
}





Port16Bit::Port16Bit(uint16_t portnumber)
: Port(portnumber)
{
}

Port16Bit::~Port16Bit()
{
}

void Port16Bit::Write(uint16_t data)
{
   __asm__ volatile("outw %0, %1" : : "a" (data), "Nd" (portnumber));
}

uint16_t Port16Bit::Read()
{
      uint16_t result;
    __asm__ volatile("inw %1, %0" : "=a" (result) : "Nd" (portnumber));
    return result;
}



Port32Bit::Port32Bit(uint16_t portnumber)
: Port(portnumber)
{
}

Port32Bit::~Port32Bit()
{
}

void Port32Bit::Write(uint32_t data)
{
   __asm__ volatile("outl %0, %1" : : "a" (data), "Nd" (portnumber));
}

uint32_t Port32Bit::Read()
{
      uint16_t result;
    __asm__ volatile("inl %1, %0" : "=a" (result) : "Nd" (portnumber));
    return result;
}



port.h soucres code:
Code:
#ifndef __PORT_H
#define __PORT_H


#include "types.h"



    class Port
    {
    protected:
        uint16_t portnumber;
        Port(uint16_t portnumber);
   ~Port();
    };
   
   
    class Port8Bit : public Port
    {
    public:
        Port8Bit(uint16_t portnumber);
   ~Port8Bit();
   virtual void Write(uint8_t data);
   virtual uint8_t Read();
    };
   
   
     class Port8BitSlow : public Port8Bit
    {
    public:
        Port8BitSlow(uint16_t portnumber);
   ~Port8BitSlow();
   virtual void Write(uint8_t data);
    };
   
   
   
      class Port16Bit : public Port
    {
    public:
        Port16Bit(uint16_t portnumber);
   ~Port16Bit();
   virtual void Write(uint16_t data);
   virtual uint16_t Read();
    };
   
   
      class Port32Bit : public Port
    {
    public:
        Port32Bit(uint16_t portnumber);
   ~Port32Bit();
   virtual void Write(uint32_t data);
   virtual uint32_t Read();
    };
   
   
#endif


Github Repos: https://github.com/mehmetprogramci/Kapilar_OS


Attachments:
Port.cpp C++ Hatası.png
Port.cpp C++ Hatası.png [ 38.81 KiB | Viewed 3370 times ]

_________________
M. Alp


Last edited by Mehmetdev1 on Fri Apr 22, 2022 5:47 am, edited 2 times in total.
Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 12:27 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
Well, I can't tell you exactly what's causing the error, but your linker is telling you what's missing. So we don't need to tell you that. But your code is confusing and (for me) hard to follow. First, you don't need to redefine portnumber in every descendant class. Since port is the progenitor of all the different port class types, referring to it will automatically refer to the class member variable in the base class. Second, you don't need all those descendant classes. It would simplify your code dramatically if you used a template class and then just instantiated that for each port type (u8, u16, u32), or used function overloads within the port class itself. And you also don't need a destructor -- there's nothing to "destroy" so you can let the compiler handle that for you automatically via the default destructor. Finally, your implementation of port*slow::write is broken: you have two labels, 1, and I'm pretty sure that's not going to assemble because I'm pretty sure you can't define two labels with the same name. But maybe this is a querk of the GNU As assembler that I just don't know about and this is perfectly okay.
Would you mind giving us a GitHub repository link and posting the error instead of a screenshot?
Edit: actually, there aren't any screenshots attached anyway, so nobody is going to know what your linker is complaining about other than you.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 1:51 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Numeric labels have a special usage in as. They have local scope and can be redefined.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 2:15 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
iansjack wrote:
Numeric labels have a special usage in as. They have local scope and can be redefined.

Oh okay, I thought that would be an assemble-time error. Though at my first quick glance I thought it would be an infinite loop so I had to re-read it and then I revised that assessment.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 3:00 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
The “f” or “b” after the number in the jump instruction refer to the first label with that number searching forwards or backwards from the current IP. It can be quite useful, particularly in macros.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 5:55 pm 
Offline
Member
Member

Joined: Mon Jul 05, 2021 6:57 pm
Posts: 118
Ethin wrote:
First, you don't need to redefine portnumber in every descendant class.


I'm looking at the code, and it doesn't do that. Only the Port class defines the portnumber field, in the subclasses portnumber only appears as a constructor parameter.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 7:15 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
davmac314 wrote:
Ethin wrote:
First, you don't need to redefine portnumber in every descendant class.


I'm looking at the code, and it doesn't do that. Only the Port class defines the portnumber field, in the subclasses portnumber only appears as a constructor parameter.

Oh I thought I saw that... My bad. And my re-reads still yielded that... Huh.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 11:42 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Show us the error message you are getting.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Thu Apr 21, 2022 11:58 pm 
Offline
Member
Member

Joined: Sat Jul 02, 2016 7:02 am
Posts: 207
A required constructor for the Port class is missing.


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Fri Apr 22, 2022 12:18 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
You are declaring that Port has a constructor. It is implicitly used by all subclasses. Therefore, you must define a constructor for class Port. And if it is empty.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Fri Apr 22, 2022 5:46 am 
Offline

Joined: Fri Apr 01, 2022 10:06 am
Posts: 23
Location: Türkiye, Uşak/Merkez
Ethin wrote:
Well, I can't tell you exactly what's causing the error, but your linker is telling you what's missing. So we don't need to tell you that. But your code is confusing and (for me) hard to follow. First, you don't need to redefine portnumber in every descendant class. Since port is the progenitor of all the different port class types, referring to it will automatically refer to the class member variable in the base class. Second, you don't need all those descendant classes. It would simplify your code dramatically if you used a template class and then just instantiated that for each port type (u8, u16, u32), or used function overloads within the port class itself. And you also don't need a destructor -- there's nothing to "destroy" so you can let the compiler handle that for you automatically via the default destructor. Finally, your implementation of port*slow::write is broken: you have two labels, 1, and I'm pretty sure that's not going to assemble because I'm pretty sure you can't define two labels with the same name. But maybe this is a querk of the GNU As assembler that I just don't know about and this is perfectly okay.
Would you mind giving us a GitHub repository link and posting the error instead of a screenshot?
Edit: actually, there aren't any screenshots attached anyway, so nobody is going to know what your linker is complaining about other than you.


Hello, The codes for the error are in the Port.cpp and port.h files. I've Created the Github Repository And Uploaded the Image Related to the Error What is the Error Exactly?

Github Repos: https://github.com/mehmetprogramci/Kapilar_OS

_________________
M. Alp


Top
 Profile  
 
 Post subject: Re: Undefined reference Error C++
PostPosted: Fri Apr 22, 2022 8:24 am 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 402
Mehmetdev1 wrote:
Ethin wrote:
Well, I can't tell you exactly what's causing the error, but your linker is telling you what's missing. So we don't need to tell you that. But your code is confusing and (for me) hard to follow. First, you don't need to redefine portnumber in every descendant class. Since port is the progenitor of all the different port class types, referring to it will automatically refer to the class member variable in the base class. Second, you don't need all those descendant classes. It would simplify your code dramatically if you used a template class and then just instantiated that for each port type (u8, u16, u32), or used function overloads within the port class itself. And you also don't need a destructor -- there's nothing to "destroy" so you can let the compiler handle that for you automatically via the default destructor. Finally, your implementation of port*slow::write is broken: you have two labels, 1, and I'm pretty sure that's not going to assemble because I'm pretty sure you can't define two labels with the same name. But maybe this is a querk of the GNU As assembler that I just don't know about and this is perfectly okay.
Would you mind giving us a GitHub repository link and posting the error instead of a screenshot?
Edit: actually, there aren't any screenshots attached anyway, so nobody is going to know what your linker is complaining about other than you.


Hello, The codes for the error are in the Port.cpp and port.h files. I've Created the Github Repository And Uploaded the Image Related to the Error What is the Error Exactly?

Github Repos: https://github.com/mehmetprogramci/Kapilar_OS


Exactly what your error screen shot says:

Port::Port(unsigned short) is missing. You declare it, use it, but don't define an implementation of it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 39 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group