Compiling ARToolKitPlus 2.1.1
October 28, 2009
This blog has moved to http://renatogarcia.blog.br
And this post to http://renatogarcia.blog.br/en/posts/compiling-artoolkitplus-2-1-1.html
20 Mar 2011 – Updated to correct an error in file arDetectMarker.cxx when using gcc 4.5
The ARToolKitPlus library isn’t developed anymore since June 2006. Nowadays is a pain compile it, there are errors with gcc 4.4, it uses the qmake builder of kde 3 series, and there are errors on internal includes. To solve this I make any patches and one project in SCons, which is better than qmake, IMO, and have less dependencies.
If you use Arch Linux there are one package in AUR with that changes, else, follow this steps:
Download the package in Arch AUR (here) and the ARToolKitPlus source (here). Put them in a same empty directory.
Run the following commands:
$>tar -xvzf artoolkitplus.tar.gz
$>unzip ARToolKitPlus_2.1.1.zip -d artoolkitplus
$>
cd artoolkitplus
$>
mv sample_multi_SConscript sample/multi/SConscript
$>
mv sample_simple_SConscript sample/simple/SConscript
$>
mv src_SConscript src/SConscript
$>
mv tools_IdPatGen_SConscript tools/IdPatGen/SConscript
$>
patch -p0 < gcc45.patch
$>
scons install prefix=$(echo ${PWD%/*})/pkg/usr
$>
mv include.patch ..
$>
cd ..
$>
patch -p0 < include.patch
Logically you must have Scons installed. If all goes well the ARTKP is compiled inside pkg directory.
April 6, 2010 at 2:52 pm
Hi, i’m trying to install artoolkitplus on linux or windows, but i’m not getting this. I try this that you posted here, but failed. Until $>patch -p0 scons install prefix=$(echo ${PWD%/*})/pkg/usr do some errors, can you help me? Add me here on wordpress.
See you!
April 8, 2010 at 2:11 am
Hi, what is the error output? These are two commands, one is: “patch -p0 < gcc44.patch". The second is "scons install prefix=$(echo ${PWD%/*})/pkg/usr". The $(echo ${PWD%/*}) thing will print the directory where are the ARToolKitPlus_2.1.1.zip and artoolkitplus.tar.gz files. This will work only in Linux, because the ${PWD%/*} is a bash command; but you can write the folder path instead.
April 20, 2010 at 1:51 pm
Hey, you seem knowledgable, maybe you can help me with this.
I think I managed to compile it using qmake on mac osx (compiling it means getting the dylib, right??!)
But how do I use it?? I try to include the header files in my project but they always fail due to some dependency or the other!
May 5, 2010 at 4:42 am
You right, after compile you will get the dynamic library.
One of problems with ARTKP is that after install, the headers files will have internal include failures. To fix this, apply the include.path, which is in AUR package.
In your project, as the ARTKP is a template library, you must include the *Impl.h files in your *.cpp files. For instance, in a myArtkpClass.hpp there must be a “#include <ARToolKitPlus/TrackerSingleMarker.h>” ,
and in myArtkpClass.cpp a “#include <ARToolKitPlus/TrackerSingleMarkerImpl.h>”
May 5, 2010 at 11:43 am
Thanks for your reply. I’ve figured it out. I just needed to put the header files of the “include” folder in the “header search path”. Did that and I have no problems.
But maybe you can help with something else, I have 2 versions of ARTKP, one that has the “Impl” files and one that doesnt. I could compile and run both. what’s the catch here??
Thanks again ; )
May 6, 2010 at 4:59 pm
Yes, this work too :-).
How do you have two versions? Did you deleted the impl files of one version?
The ARTKP has some class templates and others non template classes. The non template classes will be compiled as a dynamic library, as the normal .cpp files. Differently, the class templates don’t will be compiled when you compile the ARTKP, because they are not classes, but templates.
When you use a non template class, it’s ok only have the header with class declaration, because on linkage the definition already compiled is in the dynamic library. However, when you use a class template you will need the definition when compiling. In ARTKP the files without the Impl are abstract classes, only with declarations. It’s ok include them in yours class headers and use them as pointers, but in yours class implementations (.cpp) you will need the Impl files which have implementations of template classes that inherit from the respective abstract classes. The exception is when explicit template instantiation is used, in this case the template class with the given arguments is compiled in dynamic library.
For instance, I have a class MyClass. This class has a pointer to TrackerSingleMarker class, and includes the file ARToolKitPlus/TrackerSingleMarker.h in myClass.hpp. In myClass.cpp I include the ARToolKitPlus/TrackerSingleMarkerImpl.h, and I initialize the TrackerSingleMarker pointer with new ARToolKitPlus::TrackerSingleMarkerImpl<16,16,64,50,50>(…).
The ARTKP has a explicit template instantiation to ARToolKitPlus::TrackerSingleMarkerImpl<6,6,6, 3, 10>, and returns a pointer to this class in function createTrackerSingleMarker declared in ARToolKitPlus/ARToolKitPlus.h, this pointer is converted to a pointer to base class ARToolKitPlus::TrackerSingleMarker. If you use this function, how likely is your case, you will get a pointer to an ARToolKitPlus::TrackerSingleMarkerImpl<6,6,6, 3, 10> class. In this case, the TrackerSingleMarkerImpl.h file won’t be needed, because the ARToolKitPlus::TrackerSingleMarkerImpl<6,6,6, 3, 10> class is alredy compiled in dynamic library.
November 9, 2010 at 7:01 pm
Thanks man!
Worked like a charm!
Regards,
Alex
February 15, 2011 at 11:05 pm
Hi, i compiled ARToolkitPlus on linux using your patch and all works fine.
Now i would like to include artoolkit as a library in an eclipse c++ project.
So, I included pkg/usr/include and pkg/usr/lib in the compiler and linker options respectively.
Im copy and pasted exaclty the simple sample included in ARPlus. It is one main.cpp file , includes TrackerSingleMarkerImpl.h and instantiate
TrackerSingleMarkerImpl(width,height).
The problem is in linkage:
TrackerSingleMarkerImpl.cxx:224: undefined reference to `ARToolKitPlus::memManager’
and many errors like that in the cxx files. Could you help me please?
Thanks!!!
February 17, 2011 at 3:58 am
I resolved the problem! i needed to include ARtoolkitPlus/src as library directory:
-L/ARToolkitPlus/src
Now i can compile and link ok.
After that, in order to run an example program i added a new entry in the ld.so.conf.d directory. I created the file
/etc/ld.so.conf.d/artoolkit.conf with this content:”ARToolKitPlus/lib”.
Finally execute: sudo ldconf /etc/ld.so.conf.d/artoolkit.conf
This final step resolves the problem “error while loading shared libraries cannot open shared object file” when you run the program.
February 17, 2011 at 5:19 pm
The internal includes in the ARTKP sources is a real mess, but I never had a problem like that. I have a system wide ARTKP installation, then only the /usr/include is in my include path, not the /usr/include/ARToolKitPlus/src. I have just compiled the simple/main.cpp file, and no problems. I only found a similar problem if I don’t set the ARToolKitPlus library to linker (in g++ with -lARToolKitPlus).
To run the compiled program, if you don’t have sudo privileges, you can alternatively set the LD_LIBRARY_PATH environment variable.
March 15, 2011 at 11:50 am
Thanks for this tutorial, Renato. I have followed your instructions but I have a problem when I execute my programme. I have defined a TrackerSingleMarker instance in a .h in this way:
ARToolKitPlus::TrackerSingleMarker tr;
and I have obtained:
error: cannot declare field ‘tr’ to be of abstract type ‘ARToolKitPlus::TrackerSingleMarker’
I don’t know if your patch should solve this kind of error or if a mistake produced by myself when I declare a instance of TrackerSingleMarker. I have read your comments about template libraries so I have put the include of TrackerSingleMarkerImpl.h in .cpp. I’m using Qt 4.7, maybe the problem comes from there. Anyone has any idea about solving this problem? Thank you again.
March 15, 2011 at 6:42 pm
The TrackerSingleMarker is a pure abstract class, then it cannot be instantiated, you only can hold a pointer TrackerSingleMarker* to a class derived from TrackerSingleMarker.
When you write “ARToolKitPlus::TrackerSingleMarker tr;” ,you actually is trying instantiate a TrackerSingleMarker class using the default constructor, that is not possible.
What you must do is something like:
TrackerSingleMarker *tr = new TrackerSingleMarkerImpl<16,16,64,50,50>(args…);
or
TrackerSingleMarker *tr = createTrackerSingleMarker(args…);
or other TrackerSingleMarkerImpl template argument configuration.