Hello,

I am writing an application that uses the Loki library and I get undefined references inside loki if I use the DefaultSPStorage with std::vector<int> (it happens the same with int or using HeapStorage instead). I am developing on Mandriva 2008. Can someone please help me?

Thank you in advance
Rui

main.cpp:

#include   "include/loki/SmartPtr.h"
#include "Solution.h"
#include <iostream>

using namespace brickheuristics;

int main(void){

	typedef Loki::DefaultSPStorage< std::vector<int> > SolStorage;
	typedef Solution<
			SolStorage, 
			DummyEval, 
			DummyFeasibility, 
			DummyChanging, 
			DummyPrinting
		> MySolution;

	MySolution s = MySolution();
	cout << s.toString();
	return 0;
}

Compiler output:

g++ -O2 -g -Wall -fmessage-length=0    -c -o main.o main.cpp
g++ -o main.exe main.o
main.o: In function `Loki::SmallObjectBase<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex>::operator new(unsigned int)':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:467: undefined reference to `Loki::SmallObjAllocator::Allocate(unsigned int, bool)'
main.o: In function `Loki::SmallObjectBase<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex>::operator delete(void*, unsigned int)':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
main.o: In function `AllocatorSingleton':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:245: undefined reference to `Loki::SmallObjAllocator::SmallObjAllocator(unsigned int, unsigned int, unsigned int)'
main.o: In function `~AllocatorSingleton':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:249: undefined reference to `Loki::SmallObjAllocator::~SmallObjAllocator()'
main.o: In function `void Loki::SetLongevity<Loki::AllocatorSingleton<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex>, Loki::Private::Adapter<Loki::AllocatorSingleton<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex> > >(Loki::AllocatorSingleton<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex>*, unsigned int, Loki::Private::Adapter<Loki::AllocatorSingleton<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex> >)':
/home/rmlopes/brickheuristics/src/include/loki/Singleton.h:154: undefined reference to `Loki::Private::pTrackerArray'
/home/rmlopes/brickheuristics/src/include/loki/Singleton.h:166: undefined reference to `Loki::Private::pTrackerArray'
/home/rmlopes/brickheuristics/src/include/loki/Singleton.h:169: undefined reference to `Loki::Private::pTrackerArray'
/home/rmlopes/brickheuristics/src/include/loki/Singleton.h:175: undefined reference to `Loki::Private::AtExitFn()'
/home/rmlopes/brickheuristics/src/include/loki/Singleton.h:155: undefined reference to `Loki::Private::pTrackerArray'
main.o: In function `AllocatorSingleton':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:245: undefined reference to `Loki::SmallObjAllocator::SmallObjAllocator(unsigned int, unsigned int, unsigned int)'
main.o: In function `Loki::SmallObjectBase<Loki::SingleThreaded, 4096u, 256u, 4u, Loki::LongevityLifetime::DieAsSmallObjectParent, Loki::Mutex>::operator delete(void*, unsigned int)':
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
/home/rmlopes/brickheuristics/src/include/loki/SmallObj.h:489: undefined reference to `Loki::SmallObjAllocator::Deallocate(void*, unsigned int)'
collect2: ld returned 1 exit status
make: *** [main.exe] Error 1

hmm, the thread name is kind of missguiding
this should better be "error linking to loki"
as you can see all your .o files compile fine, but the linking is the problem

did you build the Loki library?

I know Loki is mostly a template library that need not be compiled, but I think it has some parts that maybe do need to be compiled (just like boost is with it's concurrency and networking classes). Your example looks like this could be the case.

Look at the methods that you have undefined refrence to, compile the source files that they appear in, and then when you build your main.exe link to all the required object files

Hello,

You're right, the title was a little bit unfortunate. Indeed the problem is that part of the library must be compiled. I linked the libloki.a and the problem is gone.

Thank you and kind regards,
Rui

This question has already been answered. Start a new discussion instead.