Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel
Accepted Solution

Constructors and pointer... undefined reference

ok, so i was trying to make this work..

 

MyClass *example=new Myclass();

 but its not working, i dont know what to change..

 

lets see an example:

 

newClass.h

#ifndef NEWCLASS_H_
#define NEWCLASS_H_

class newClass {
public:
	newClass();
	virtual ~newClass();
};

#endif /* NEWCLASS_H_ */

 newClass.cpp

#include "newClass.h"

newClass::newClass() {
	// TODO Auto-generated constructor stub

}

newClass::~newClass() {
	// TODO Auto-generated destructor stub
}

 applicationui.cpp

 

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>
#include <bb/cascades/Page>
#include <bb/cascades/Container>
#include <bb/cascades/StackLayout>
#include <bb/cascades/ImageView>
#include <bb/cascades/Label>
#include <bb/cascades/TextStyle>
#include <bb/cascades/SystemDefaults>
#include <bb/cascades/TitleBar>


#include <newClass.h>


using namespace bb::cascades;

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);
    if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) {
        // This is an abnormal situation! Something went wrong!
        // Add own code to recover here
        qWarning() << "Recovering from a failed connect()";
    }
    // initial load
    onSystemLanguageChanged();
newClass *temp=new newClass();

}

void ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("FirstAppAlone_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

 error:

C:\Users\imnotgoingtotellyoumyuser\ndk-10.2-workspace\FirstAppA\x86/../src/applicationui.cpp:93: undefined reference to `newClass::newClass()'

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Constructors and pointer... undefined reference

Hi!
Try replacing
#include <newClass.h>
with
#include "newClass.h"

<...> searches in system include path, "..." searches locally.

If this won't help, please paste the full compiler output, there may be more errors above this one.

Althought not a requirement, in Qt class names are usually capitalized: MyClass etc.

Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: Constructors and pointer... undefined reference

same Smiley Sad

 

here it is:

15:17:30 **** Incremental Build of configuration Simulator-Debug for project FirstAppAlone ****
make -j8 Simulator-Debug 
make -C .//translations -f Makefile update
make[1]: Entering directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/translations'
C:/bbndk/host_10_2_0_15/win32/x86/usr/bin/lupdate FirstAppAlone.pro
Updating 'FirstAppAlone.ts'...
    Found 1 source text(s) (0 new and 1 already existing)
make[1]: Leaving directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/translations'
make -C .//translations -f Makefile release
make[1]: Entering directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/translations'
C:/bbndk/host_10_2_0_15/win32/x86/usr/bin/lrelease FirstAppAlone.pro
Updating 'C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/translations/FirstAppAlone.qm'...
    Generated 0 translation(s) (0 finished and 0 unfinished)
    Ignored 1 untranslated source text(s)
make[1]: Leaving directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/translations'
make -C ./x86 -f Makefile debug
make[1]: Entering directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/x86'
make -f Makefile.Debug
make[2]: Entering directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/x86'
qcc -Vgcc_ntox86 -c -Wc,-include -Wc,o-g/.obj/FirstAppAlone -Wno-psabi -lang-c++ -fstack-protector -fstack-protector-all -g -Wno-psabi -Wall -W -D_REENTRANT -DQT_NO_IMPORT_QT47_QML -DQ_OS_BLACKBERRY -DQT_DECLARATIVE_DEBUG -DQT_DECLARATIVE_LIB -DQT_CORE_LIB -DQT_SHARED -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/share/qt4/mkspecs/blackberry-x86-qcc -I../../FirstAppAlone -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/include/qt4/QtCore -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/include/qt4/QtDeclarative -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/include/qt4 -I../src -Io-g/.moc -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/include -Ic:/bbndk/target_10_2_0_1155/qnx6/usr/include/freetype2 -I. -o o-g/.obj/applicationui.o ../src/applicationui.cpp
../src/applicationui.cpp: In constructor 'ApplicationUI::ApplicationUI(bb::cascades::Application*)':
../src/applicationui.cpp:93:11: warning: unused variable 'temp' [-Wunused-variable]
qcc -Vgcc_ntox86 -lang-c++ -Wl,-rpath-link,C:/bbndk/target_10_2_0_1155/qnx6/x86/lib -Wl,-rpath-link,C:/bbndk/target_10_2_0_1155/qnx6/x86/usr/lib -Wl,-rpath-link,C:/bbndk/target_10_2_0_1155/qnx6/x86/usr/lib/qt4/lib -o o-g/FirstAppAlone o-g/.obj/applicationui.o o-g/.obj/main.o o-g/.obj/moc_applicationui.o    -LC:/bbndk/target_10_2_0_1155/qnx6/x86/lib -LC:/bbndk/target_10_2_0_1155/qnx6/x86/usr/lib -LC:/bbndk/target_10_2_0_1155/qnx6/x86/usr/lib/qt4/lib -LC:/bbndk/target_10_2_0_1155/qnx6//usr/lib/qt4/lib -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps 
o-g/.obj/applicationui.o: In function `ApplicationUI':
C:\Users\luisdaniel\ndk-10.2-workspace\FirstAppAlone\x86/../src/applicationui.cpp:93: undefined reference to `newClass::newClass()'
cc: C:/bbndk/host_10_2_0_15/win32/x86/usr/bin/ntox86-ld caught signal 1
make[2]: Leaving directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/x86'
make[2]: *** [o-g/FirstAppAlone] Error 1
make[1]: Leaving directory `C:/Users/luisdaniel/ndk-10.2-workspace/FirstAppAlone/x86'
make[1]: *** [debug] Error 2
make: *** [Simulator-Debug] Error 2

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Constructors and pointer... undefined reference

Just out of principle I would avoid using new in any class name or variable declarations.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Constructors and pointer... undefined reference

From the log it seems that newClass.cpp is not being compiled.
Also, newClass.o is missing when the linker is called.

Please try the following steps:

1) Make sure that this file is present in config.pri file. It should look similar to this:
SOURCES += $$quote($$BASEDIR/src/filename.cpp)
From .pro/.pri files Makefile script is generated.

2) If it's there, try cleaning the project and rebuilding. Maybe the Makefile wasn't regenerated after the class was added.

If this also won't help, please attach the archived project so we can experiment with it.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Constructors and pointer... undefined reference

[ Edited ]

Yeah it's a naming problem, change the class name to something else.

 

Capitalise the first letter and avoid using C++ keywords in your class names.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Constructors and pointer... undefined reference

... or perhaps not seems to accept it if you do a clean build of your project.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Constructors and pointer... undefined reference

[ Edited ]

Ok after some testing it seems adding any class in to applicatioui requires a rebuild ot the project, not sure why and can't be bothered to investigate. Possibly the fact that the pointer is unused and therefore will get optimised out by the compiler may be a factor.

 

Any way solution is to rebuild.

 

[Edit] Please set the solution to zmey's answer above, assuming the rebuild cleared your problem of course.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Constructors and pointer... undefined reference

[ Edited ]

When files are added to the project, IDE adds them to .pro or .pri file.

But that's not enough. Qmake must be runned to regenerate Makefile which is used for compilation. It seems this step isn't done by IDE, so clean & rebuild is required.

I'll retest this and will submit a JIRA ticket if this is the case.

 

upd: confirmed. https://www.blackberry.com/jira/browse/TOOL-2393


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 20
Registered: ‎09-02-2013
My Device: Dev Alpha B
My Carrier: Claro Codetel

Re: Constructors and pointer... undefined reference

none has work yet... im thinking on creating another proyect to test :'(