09-06-2012 11:32 AM
I have some materials in subfolders of my project, and use the include with full path to add it:
#include <materials/dataservices/DataServiceConfig.hpp>
this compiles well, but when i try to create the object i get this error:
undefined reference to `DataServiceConfig::DataServiceConfig(QObject*)'
what am I doing wrong?
Solved! Go to Solution.
09-06-2012 12:28 PM
Is there a warning about the include? Usually <blah.h> is for headers in the system path, and you would use "blah.h" for project headers.
Is DataServiceConfig in a namespace?
09-07-2012 03:06 AM
09-07-2012 09:31 AM - edited 09-07-2012 09:40 AM
You don't need to worry about namespaces. Only reason I ask is because you can put classes in a namespace, but if you don't enable it or include it in the name, you can't see it.
But the "undefined reference" in an error usually means you can see the declaration in the header, but the definition wasn't compiled or linked by the compiler.
Some general times you'd see this:
1) you include and reference headers for a library but don't actually link the library at compile time with the -l<name> flag.
2) you can include the header, but the source isn't compiled/linked
3) the declare method arguments in the header differ from what is defined in the source
4) you don't prepend the classname on the method or constructor name in the source
So some things too look for:
* Are you using a Makefile project, or a managed project? (makes a difference on how the source file is included)
* Does the console output show your CPP file being compiled. (if not, it probably wasn't included. clean the project first to make sure you see the full source being built)
* If you are using a Makefile project and its not being included, do you explicitly include the file, or are you using a wildcard? I found with classes in subdirectories, just using a wildcard wasn't including the source files. If that is the case, check out this thread: http://supportforums.blackberry.com/t5/Native-Deve
* If its a managed project, is the file extension .cpp? The eclipse plugin has a set list it looks for if others are specified.
If those don't help...
Another reason for undefined reference would be in the arguments in the method don't match. Usually the error message would suggest candidates that have the same method name, but different arguments.
Can you post:
* the full error message
* copy of where you declare the method in your class
* copy of where you define it in the source file (you can cut out the body.)
09-07-2012 10:58 AM
* I think it is a managed build, i did not change anything from the Momentics default.
* I don't see the file (or any other of my materials) mentioned in the build output. That means they are not included, correct?
So this is most likely the error. How do i change that? (and where!)
I used "properties, c/c++ build, paths and symbols, includes, gnu c, add, workspace" to add the three directories, following instructions from google (took me about an hour).
In "properties, c/c++ build" the checkbox "generate makefiles automatically" is not checked, but if i select it the build fails as well.
* Yes, the file extension is cpp.
Here is the declaration from the hpp file:
class DataServiceConfig : public QObject
{
Q_OBJECT
public:
DataServiceConfig(QObject* parent = 0);
virtual ~DataServiceConfig();
and here the (not very complex) part from the cpp:
#include "DataServiceConfig.hpp"
DataServiceConfig::DataServiceConfig(QObject* parent) {
//void
}
DataServiceConfig::~DataServiceConfig() {
// void
}
So i suspect i have to declare the usage of these subfolders somewhere?
09-07-2012 11:00 AM
Usually this happens when you have this in your include file:
class MyClass
{
public:
MyClass(MyThing*);
private:
MyThing* m_thing;
};
but don't have this in your MyClass.cpp:
MyClass::MyClass(MyThing* thing) :
m_thing(thing)
{
}
In other words, you have the declaration -- so the things that use your class compile -- but you don't have the implementation, so the linker complains that it can't find it.
Stuart
09-07-2012 11:20 AM - edited 09-07-2012 11:34 AM
Are you doing a cascades project? I had issues with Q_OBJECT in a managed build because it has to run some 'moc' command or something. ...thats probably an issue for another time though. (I ended up having to copy one of the sample projects with a PRO file because I couldn't figure out how to get a default empty project for it... it was stupid.)
Your files look fine.
You can test if its a subdirectory issue by just moving everything into the root and see if that compiles.
Momentics should've asked you if you wanted Makefile vs Managed when you created the project. If it is managed, and the files are under the source directory, subdirectories should be included automatically. I can't remember if there was a default src directory or not. If not, you should make sure that its marked as a source directory. The icon should be different. You can do add -> new source folder also. I don't have momentics on this machine to see the defaults.
09-07-2012 11:26 AM
09-10-2012 05:46 AM - edited 09-10-2012 09:20 AM
smacmartin wrote:
In other words, you have the declaration -- so the things that use your class compile -- but you don't have the implementation, so the linker complains that it can't find it.
Stuart
It seems that this was the issue!
I removed the QObject-stuff from all classes, as they are just beans to store data, and also removed all constructor declarations.
The project compiles now, and i can also move the classes to the subfolders without any change, so that was not the issue.
Edit: Subfolders work only after putting them into the .pro file in the SOURCES/HEADERS section
If only the error messages would be a bit less general, searching for one returns a myriad of different issues that is really difficult to sort through.
Anyhow, back on track now!