Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ undefined reference class constructor

I'm trying to use a library where one of the classes has a constructor like so:

public:
AreaNodeIndex(size_t cacheSize);

I'm trying to instantiate an object of this class in my program like so:

size_t const cacheSize = 50000;
AreaNodeIndex areaNodeIndex(cacheSize);

The linker gives me the following error:

main.o: In function `main':
make: Leaving directory `/home/Dev/_quicktest_build'
main.cpp:(.text+0x212): undefined reference to  
osmscout::AreaNodeIndex::AreaNodeIndex(unsigned int)

I think I have the necessary includes and I'm linking to the library with the compiler. For example, if I try to instantiate the object without any arguments on purpose I get this error:

../quicktest/main.cpp: In function ‘int main()’:
../quicktest/main.cpp:36: error: no matching function for call to ‘osmscout::AreaNodeIndex::AreaNodeIndex()’
/usr/local/include/osmscout/AreaNodeIndex.h:75: note: candidates are: osmscout::AreaNodeIndex::AreaNodeIndex(size_t)
/usr/local/include/osmscout/AreaNodeIndex.h:33: note:     osmscout::AreaNodeIndex::AreaNodeIndex(const osmscout::AreaNodeIndex&)

So I can see the correct prototype (though here it says size_t and before it said unsigned int)...

I can use other parts of the library fine. Here are the actual source files for the class in question:

http://libosmscout.git.sourceforge.net/git/gitweb.cgi?p=libosmscout/libosmscout;a=blob;f=libosmscout/include/osmscout/AreaNodeIndex.h

http://libosmscout.git.sourceforge.net/git/gitweb.cgi?p=libosmscout/libosmscout;a=blob;f=libosmscout/src/osmscout/AreaNodeIndex.cpp

I'm pretty lost as to why this is happening. I feel like I've missed something obvious.

*In response to the replies: The library gets size_t from "sys/types.h", so I don't think we're using different versions. The library was compiled on my system with the same compiler (g++, linux). Changing the 'const' specifier location has no effect.

I am linking to the library. As I mentioned, I can use other classes from the library without issue. Here's the linking command:

g++ -Wl,-O1 -Wl,-rpath,/home/QtSDK/Desktop/Qt/473/gcc/lib -o quicktest main.o -L/home/QtSDK/Desktop/Qt/473/gcc/lib -losmscout -lpthread

The library name is 'osmscout'.

kfl

like image 622
kfl Avatar asked Feb 19 '26 22:02

kfl


1 Answers

Possible cause of the problem in your case could be because of mixing of different size_t as mentioned by @rodrigo. For consistency maybe you can include <cstddef> where you are using size_t unless your project declares it own typedef for size_t. Please refer the link below.

Please refer Does "std::size_t" make sense in C++?

Hope this helps!

like image 168
another.anon.coward Avatar answered Feb 21 '26 13:02

another.anon.coward



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!