undefined reference to `jsonxx::Object::Object()'

I have to use jsonxx library in my project. But calling this line jsonxx::Object out; throws an error - `undefined reference to jsonxx::Object::Object()'` and `undefined reference to jsonxx::Object::~Object()'`

Here is the full code

1
2
3
4
5
6
#include "jsonxx.h"

int main()
{
    jsonxx::Object out;
}


How to fix this?
Last edited on
Are you building jsonxx.cc too?
I put both jsonxx.h and jsonxx.cc next to main.cpp. So there are three files in the folder. Then run the code as usual (with VS Code extension). Maybe jsonxx needs some special tools for running?
It's not enough to just put files near each other. The compiler has to know to compile each file, and the linker has to know to link them together.

Does your IDE have the concept of a "project" or similar?
I don't really understand what do you mean under "concept of a project". It always compiled with multiple files.
It always compiled with multiple files.


How does it know what files to compile? It's not compiling every file on your hard drive, right? So somehow, it knows which files to compile? How does it know?

However it knows, it's missing the one that contains the code that is jsonxx::Object::Object() (the constructor for a jsonxx::Object) and the code that is jsonxx::Object::~Object() (the deconstructor for a jsonxx::Object)
Last edited on
How does it know what files to compile?


I set up VS Code extension for this
Your issue is that the code in your main is not being linked with the code in jsonxx.cc. That's all I can say without knowing more information.
Is jsonxx.cc being compiled?
What commands are being run to compile your project?
I set up VS Code extension for this


Well it didn't work.
But it works with other projects. :-)
Try changing .cc to .cpp?

Otherwise, this conversion can't go much further unless you can confirm that jsonxx.cc is even being compiled.
Last edited on
1
2
3
4
tempCodeRunnerFile.cpp: In function 'int main()':
tempCodeRunnerFile.cpp:3:5: error: 'jsonxx' has not been declared
     jsonxx::Object out;
     ^~~~~~
That's a different error now. If that's on line 3, I assume that means you didn't #include anything? The line number no longer matches your original post, so it means your code is changed.
Last edited on
1
2
3
4
5
6
#include "jsonxx.h"

int main()
{
    jsonxx::Object out;
}
Does your editor use a script or make file to build the program?
Can you show it to us.
I figured out that had to use cmake. It worked! Thank you everyone!
Topic archived. No new replies allowed.