Avogadro/standalone interface

Hi all,

Am writing some code to calculate internal surface area of molecules/structures as a standalone and making an interface for a plugin to Avogadro, with an eye for more development in the future.

Here’s the problem I have at the moment:

in objectextension.h :

#ifndef

#include <avogadro/extension, widget and primative>
#include <Q_libs_that_are_relavent>

#include “interface.h” //this is my class, moving this from the .h to the .cpp changes the error
#include “the_ui_bit.h”

//have instantiated interface here (haha, desparation)
//did a forward declaration and reassigned in .cpp as well, no difference (obviously I tried all these at different times)

namespace Avogadro{

//have instantiated interface here

class SASACalcFileDialog: public QDialog, private Ui::SASACalcFileDialog
{
Q_OBJECT

//have instatiated interface here

public:
explicit SASACalcFileDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ) ;
~SASACalcFileDialog();
public slots:
//there are slots here but not relevant
private:
interface *my_interface ; //<–here is where I am currently instantiating but moving this around yeilds the same two
// interface needs to be a local variable
};

//below here is the code to deal with the extension to avogadro, this works.

in objectextension.cpp:

#include “objectextension.h”

//have instantiated interface here

namespace Avogadro
{
//slots and other useful stuff goes here…

//have instantiated interface here

void SASACalcFileDialog::setup()
{
//have instatiated interface here
//simple math and function calls are here, inconsequential as this works.

interface->setup_geometry(xyzFile, datFile, ffFile) ; <-- this is line 156, and where it is necessary to call this method.

}
}

in interface.h:

#include <a_bunch_of_stuff>

class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file

private:
double area ;
sasa_geometry *thisGeometry ;
};

in interface.cpp:

#include “sasa_interface.h”

using namespace std ;
using namespace Eigen ;

sasa_interface::sasa_interface() //look a constructor!
{}

bool sasa_interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

currently I am getting an undefined reference to interface::setup_geometry(QString, QString, Qstring) in objectextension.cpp on line 156 error,

substituting: interface myInterface ; in the header (not instatiating as a pointer) gives an undefined reference to both the constructor in objectextension.cpp line 36 and the setup_geometry(…) method. I assume this increase in errors is due to the object not really being instantiated when its declared as a pointer, and the first time a method is called is the first time the object is truly accessed/refered to.

forward declaration and instatiation as an object (not a pointer) yeilds redefinition of class interface errors.

I am quite new to c++ and although I’ve encountered this before none of the prescription ways of dealing with this seem to be working, this is also my first project so please be mindful that what I say and what I mean may not necessarily coincide, clarification supplied on request and achieved through communication.

I am hoping this is a simple problem that most people encounter in their first implementation.

Cheers if you look at this,

Mark

On Wed, Mar 2, 2011 at 9:38 AM, Lewis, Mark M.A.Lewis@liverpool.ac.uk wrote:

in interface.h:
class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file
[snip]
};

in interface.cpp:

#include “sasa_interface.h”
[snip]
sasa_interface::sasa_interface() //look a constructor!
{}

bool sasa_interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

These functions are defined as belonging to class “interface”, but
implemented as “sasa_interface”. Remove the "sasa_"s from
interface.cpp and try again.

Dave

There are typo’s in this example, interface is named sasa_interface throughout the code, errors introduced during copy/paste then edit for ease of reading :

Error is due to calling an object not in namespace Avogadro from an extension class, errors follow code.

in objectextension.h :

#ifndef

#include <avogadro/extension, widget and primative>
#include <Q_libs_that_are_relavent>

#include “interface.h” //this is my class, moving this from the .h to the .cpp changes the error
#include “the_ui_bit.h”

//have instantiated interface here (haha, desparation)
//did a forward declaration and reassigned in .cpp as well, no difference (obviously I tried all these at different times)

namespace Avogadro{

//have instantiated interface here

class SASACalcFileDialog: public QDialog, private Ui::SASACalcFileDialog
{
Q_OBJECT

//have instatiated interface here

public:
explicit SASACalcFileDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ) ;
~SASACalcFileDialog();
public slots:
//there are slots here but not relevant
private:
interface *my_interface ; //<–here is where I am currently instantiating but moving this around yeilds the same two
// interface needs to be a local variable
};

//below here is the code to deal with the extension to avogadro, this works.

in objectextension.cpp:

#include “objectextension.h”

//have instantiated interface here

namespace Avogadro
{
//slots and other useful stuff goes here…

//have instantiated interface here

void SASACalcFileDialog::setup()
{
//have instatiated interface here
//simple math and function calls are here, inconsequential as this works.

interface->setup_geometry(xyzFile, datFile, ffFile) ; <-- this is line 156, and where it is necessary to call this method.

}
}

in interface.h:

#include <a_bunch_of_stuff>

class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file

private:
double area ;
geometry *thisGeometry ;
};

in interface.cpp:

#include “interface.h”

using namespace std ;
using namespace Eigen ;

interface::interface() //look a constructor!
{}

bool interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

currently I am getting an undefined reference to interface::setup_geometry(QString, QString, Qstring) in objectextension.cpp on line 156 error,

substituting: interface myInterface ; in the header (not instatiating as a pointer) gives an undefined reference to both the constructor in objectextension.cpp line 36 and the setup_geometry(…) method. I assume this increase in errors is due to the object not really being instantiated when its declared as a pointer, and the first time a method is called is the first time the object is truly accessed/refered to.

forward declaration and instatiation as an object (not a pointer) yields redefinition of class interface errors.

Thanks,

Mark


From: Lewis, Mark [M.A.Lewis@liverpool.ac.uk]
Sent: 02 March 2011 14:38
To: avogadro-devel@lists.sourceforge.net
Subject: [Avogadro-devel] avogadro/standalone interface

Hi all,

Am writing some code to calculate internal surface area of molecules/structures as a standalone and making an interface for a plugin to Avogadro, with an eye for more development in the future.

Here’s the problem I have at the moment:

in objectextension.h :

#ifndef

#include <avogadro/extension, widget and primative>
#include <Q_libs_that_are_relavent>

#include “interface.h” //this is my class, moving this from the .h to the .cpp changes the error
#include “the_ui_bit.h”

//have instantiated interface here (haha, desparation)
//did a forward declaration and reassigned in .cpp as well, no difference (obviously I tried all these at different times)

namespace Avogadro{

//have instantiated interface here

class SASACalcFileDialog: public QDialog, private Ui::SASACalcFileDialog
{
Q_OBJECT

//have instatiated interface here

public:
explicit SASACalcFileDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ) ;
~SASACalcFileDialog();
public slots:
//there are slots here but not relevant
private:
interface *my_interface ; //<–here is where I am currently instantiating but moving this around yeilds the same two
// interface needs to be a local variable
};

//below here is the code to deal with the extension to avogadro, this works.

in objectextension.cpp:

#include “objectextension.h”

//have instantiated interface here

namespace Avogadro
{
//slots and other useful stuff goes here…

//have instantiated interface here

void SASACalcFileDialog::setup()
{
//have instatiated interface here
//simple math and function calls are here, inconsequential as this works.

interface->setup_geometry(xyzFile, datFile, ffFile) ; <-- this is line 156, and where it is necessary to call this method.

}
}

in interface.h:

#include <a_bunch_of_stuff>

class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file

private:
double area ;
sasa_geometry *thisGeometry ;
};

in interface.cpp:

#include “sasa_interface.h”

using namespace std ;
using namespace Eigen ;

sasa_interface::sasa_interface() //look a constructor!
{}

bool sasa_interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

currently I am getting an undefined reference to interface::setup_geometry(QString, QString, Qstring) in objectextension.cpp on line 156 error,

substituting: interface myInterface ; in the header (not instatiating as a pointer) gives an undefined reference to both the constructor in objectextension.cpp line 36 and the setup_geometry(…) method. I assume this increase in errors is due to the object not really being instantiated when its declared as a pointer, and the first time a method is called is the first time the object is truly accessed/refered to.

forward declaration and instatiation as an object (not a pointer) yeilds redefinition of class interface errors.

I am quite new to c++ and although I’ve encountered this before none of the prescription ways of dealing with this seem to be working, this is also my first project so please be mindful that what I say and what I mean may not necessarily coincide, clarification supplied on request and achieved through communication.

I am hoping this is a simple problem that most people encounter in their first implementation.

Cheers if you look at this,

Mark

Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-devel

On Mar 3, 2011 3:24 AM, “Lewis, Mark” M.A.Lewis@liverpool.ac.uk wrote:

in interface.h:

#include <a_bunch_of_stuff>

class interface
{

};

Do you have header guards in interface.h? (E.g. #ifndef SASA_INTERFACE_H,
etc surrounding class definition).

Dave

Hi All,

I have located the source of the problem, through collaboration with Jens Thomas. He pointed out that I had neglected to include the interface implementation in the CMakeFiles.txt. So in the future, any switching between ‘redefinition of class’ and ‘undefined reference to’ errors which refuse to be dealt with in the standard way, look in your CMakeFiles.txt and hope it’s an easy fix.

Cheers for the support,

Mark


From: Lewis, Mark
Sent: 03 March 2011 08:24
To: Lewis, Mark; avogadro-devel@lists.sourceforge.net
Subject: RE: avogadro/standalone interface

There are typo’s in this example, interface is named sasa_interface throughout the code, errors introduced during copy/paste then edit for ease of reading :

Error is due to calling an object not in namespace Avogadro from an extension class, errors follow code.

in objectextension.h :

#ifndef

#include <avogadro/extension, widget and primative>
#include <Q_libs_that_are_relavent>

#include “interface.h” //this is my class, moving this from the .h to the .cpp changes the error
#include “the_ui_bit.h”

//have instantiated interface here (haha, desparation)
//did a forward declaration and reassigned in .cpp as well, no difference (obviously I tried all these at different times)

namespace Avogadro{

//have instantiated interface here

class SASACalcFileDialog: public QDialog, private Ui::SASACalcFileDialog
{
Q_OBJECT

//have instatiated interface here

public:
explicit SASACalcFileDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ) ;
~SASACalcFileDialog();
public slots:
//there are slots here but not relevant
private:
interface *my_interface ; //<–here is where I am currently instantiating but moving this around yeilds the same two
// interface needs to be a local variable
};

//below here is the code to deal with the extension to avogadro, this works.

in objectextension.cpp:

#include “objectextension.h”

//have instantiated interface here

namespace Avogadro
{
//slots and other useful stuff goes here…

//have instantiated interface here

void SASACalcFileDialog::setup()
{
//have instatiated interface here
//simple math and function calls are here, inconsequential as this works.

interface->setup_geometry(xyzFile, datFile, ffFile) ; <-- this is line 156, and where it is necessary to call this method.

}
}

in interface.h:

#include <a_bunch_of_stuff>

class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file

private:
double area ;
geometry *thisGeometry ;
};

in interface.cpp:

#include “interface.h”

using namespace std ;
using namespace Eigen ;

interface::interface() //look a constructor!
{}

bool interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

currently I am getting an undefined reference to interface::setup_geometry(QString, QString, Qstring) in objectextension.cpp on line 156 error,

substituting: interface myInterface ; in the header (not instatiating as a pointer) gives an undefined reference to both the constructor in objectextension.cpp line 36 and the setup_geometry(…) method. I assume this increase in errors is due to the object not really being instantiated when its declared as a pointer, and the first time a method is called is the first time the object is truly accessed/refered to.

forward declaration and instatiation as an object (not a pointer) yields redefinition of class interface errors.

Thanks,

Mark


From: Lewis, Mark [M.A.Lewis@liverpool.ac.uk]
Sent: 02 March 2011 14:38
To: avogadro-devel@lists.sourceforge.net
Subject: [Avogadro-devel] avogadro/standalone interface

Hi all,

Am writing some code to calculate internal surface area of molecules/structures as a standalone and making an interface for a plugin to Avogadro, with an eye for more development in the future.

Here’s the problem I have at the moment:

in objectextension.h :

#ifndef

#include <avogadro/extension, widget and primative>
#include <Q_libs_that_are_relavent>

#include “interface.h” //this is my class, moving this from the .h to the .cpp changes the error
#include “the_ui_bit.h”

//have instantiated interface here (haha, desparation)
//did a forward declaration and reassigned in .cpp as well, no difference (obviously I tried all these at different times)

namespace Avogadro{

//have instantiated interface here

class SASACalcFileDialog: public QDialog, private Ui::SASACalcFileDialog
{
Q_OBJECT

//have instatiated interface here

public:
explicit SASACalcFileDialog( QWidget *parent = 0, Qt::WindowFlags f = 0 ) ;
~SASACalcFileDialog();
public slots:
//there are slots here but not relevant
private:
interface *my_interface ; //<–here is where I am currently instantiating but moving this around yeilds the same two
// interface needs to be a local variable
};

//below here is the code to deal with the extension to avogadro, this works.

in objectextension.cpp:

#include “objectextension.h”

//have instantiated interface here

namespace Avogadro
{
//slots and other useful stuff goes here…

//have instantiated interface here

void SASACalcFileDialog::setup()
{
//have instatiated interface here
//simple math and function calls are here, inconsequential as this works.

interface->setup_geometry(xyzFile, datFile, ffFile) ; <-- this is line 156, and where it is necessary to call this method.

}
}

in interface.h:

#include <a_bunch_of_stuff>

class interface
{
public:
interface() ;
bool setup_geometry(QString, QString, QString) ; //args: xyz_file, dat_file, ff_file

private:
double area ;
sasa_geometry *thisGeometry ;
};

in interface.cpp:

#include “sasa_interface.h”

using namespace std ;
using namespace Eigen ;

sasa_interface::sasa_interface() //look a constructor!
{}

bool sasa_interface::setup_geometry(QString xyz_filePath, QString dat_filePath, QString ff_FilePath) //and here is where the functionality lives
{
//code that is nice and works
}

currently I am getting an undefined reference to interface::setup_geometry(QString, QString, Qstring) in objectextension.cpp on line 156 error,

substituting: interface myInterface ; in the header (not instatiating as a pointer) gives an undefined reference to both the constructor in objectextension.cpp line 36 and the setup_geometry(…) method. I assume this increase in errors is due to the object not really being instantiated when its declared as a pointer, and the first time a method is called is the first time the object is truly accessed/refered to.

forward declaration and instatiation as an object (not a pointer) yeilds redefinition of class interface errors.

I am quite new to c++ and although I’ve encountered this before none of the prescription ways of dealing with this seem to be working, this is also my first project so please be mindful that what I say and what I mean may not necessarily coincide, clarification supplied on request and achieved through communication.

I am hoping this is a simple problem that most people encounter in their first implementation.

Cheers if you look at this,

Mark

Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-devel

On Thu, Mar 3, 2011 at 9:27 AM, Lewis, Mark M.A.Lewis@liverpool.ac.uk wrote:

Hi All,

I have located the source of the problem, through collaboration with Jens Thomas. He pointed out that I had neglected to include the interface implementation in the CMakeFiles.txt. So in the future, any switching between ‘redefinition of class’ and ‘undefined reference to’ errors which refuse to be dealt with in the standard way, look in your CMakeFiles.txt and hope it’s an easy fix.

Glad you got it working, it is often easier for us if you are able to
simply post a snapshot of your work somewhere (such as GitHub, or a
tarball). Thanks to Jens for helping you get to the bottom of it.
Straight copy and paste to places like pastebin can often reveal
issues you didn’t notice too.

Marcus