1

I'm attempting to write code for an ATxmega16E5 using Atmel Studio 7. I've had a long search around the forums and cannot make head nor tail of the other suggestions that seem to be similar to my own issue. (A lot of suggestions indicate to change compiling options, which I have no idea how to do this in Atmel Studio).

Basically, I've included my class GPP.h BUT, when I try to instantiate a class in main.cpp it comes back as a series of undefined references to all functions including the constructor.

EDIT: Reduced the amount of included code to focus on the main issues at hand, mainly, the files don't seem to be linking.

main.cpp :

//INCLUDES
#include "GPP.h"

//MAIN FUNCTION
int main()
{

    GPP *gpp = new GPP();

    //Turn on system power
    gpp->setPowerPin();
    gpp->screenOn();

    // ...etc (just makes some function calls

    // ...
    while(1);
}

GPP.h:

#ifndef GPOWERPACK_H
#define GPOWERPACK_H


class GPP
{   
public:

    GPP();
    //~GPP();

    void setPowerPin();
    void screenOn();
    void SPI_Init();
    void SPI_SendNext();
    void displayLogo();     
};
#endif

Any help would be fantastic to help grow my understanding of cpp. I have coded in c and java previously.

Atmel Makefile is quite long, Could display sections on request?

valiano
  • 16,433
  • 7
  • 64
  • 79
  • 1
    Do you come from a Java or C# environment? Because you attempt to dynamically allocate data for variables that aren't pointers. For example `SPI_DATA_BUFFER = new LinkedList()`. That's not now it works in C++. Perhaps you should start over [by reading a couple of good beginner books](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude Oct 19 '17 at 08:54
  • 1
    As for your errors, it indicates that you don't actually build with `GPP.cpp`. Because if you did you should not have gotten the linker errors, but instead compiler errors (for example about the wrong use of `new`). – Some programmer dude Oct 19 '17 at 08:55
  • 1
    1) Did you link all of the object files together? Show us the command line with which you compile / link files into executable. 2) What's with those unnecessary `new`s? Do you really need to allocate the instances dynamically? – Algirdas Preidžius Oct 19 '17 at 08:56
  • 1
    Lastly, please take some time to [take the SO tour](http://stackoverflow.com/tour), [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask), and learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve). – Some programmer dude Oct 19 '17 at 08:56
  • Thank you for the tips. I'm new around here. I come from a java environment. SPI_DATA_BUFFER completely slipped my attention - so thank you for pulling that up for me. Genuine question: What should I consider when determining whether to make a dynamic or (static is the opposite?) allocation of a class? I'll have a read of the 'good questions' link too thanks Some programmer dude. :) Algirdas, I am using Atmel Studio to do the compiling, which is part of the problem, I don't know how to change the commands within the Atmel program itself. Any ideas? – Brother Maestro Oct 19 '17 at 11:58

1 Answers1

0

For anyone using Atmel Studio for the first time. And those who have simply forgotten the basics of makefiles.

I figured out a simple way to resolve my linker issue.

The error 'undefined reference' occurred because I had not included the files GPP.cpp and GPP.h in the project build.

The fix: 1) Open the "Solution Explorer"

2) Right click on your project, go to add -> existing item

3) select the files you are including/ files relevant to your project build and click

Apologies for the misguided question. Seems a simple mistake in hindsight