OpenNI / OpenNI2

OpenNI2
Apache License 2.0
432 stars 893 forks source link

Fixes for Building under Linux #3

Closed zhemao closed 11 years ago

zhemao commented 11 years ago

I had to make some changes in order to get OpenNI2 to build on Linux.

The IsZero function in the XnLib code had to moved below the definition of Abs because it depended on the Abs definition.

In the Makefile for NiViewer, I added -pthread -lrt to the linker flags to pull in the necessary libraries.

eddiecohen commented 11 years ago

On which Linux are you trying to compile (I compile on Ubuntu 12.04 and didn't encounter those issues)?

zhemao commented 11 years ago

Arch Linux

tomoto commented 11 years ago

Hi zhemao,

I do not think "Arch Linux" is sufficient for OpenNI people to figure out the root cause and the right solution. If you could get more specific version information about your distribution and your compiler, it might help.

To get the information about your distribution, see http://www.cyberciti.biz/faq/find-linux-distribution-name-version-number/ . To get the same for your compiler, run gcc -v.

For example, here are the information of my Linux where I did not have the same problem either.

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=12.10
DISTRIB_CODENAME=quantal
DISTRIB_DESCRIPTION="Ubuntu 12.10"
NAME="Ubuntu"
VERSION="12.10, Quantal Quetzal"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu quantal (12.10)"
VERSION_ID="12.10"
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.2-2ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.7.2 (Ubuntu/Linaro 4.7.2-2ubuntu1) 

(Edited: fixed a slight copy & paste mistake)

zhemao commented 11 years ago

gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7.2/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --disable-ppl-version-check --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release
Thread model: posix
gcc version 4.7.2 (GCC)

uname -a

Linux daxiongmao 3.6.11-1-ARCH #1 SMP PREEMPT Tue Dec 18 08:57:15 CET 2012 x86_64 GNU/Linux

And here are the compilation errors I get when trying to compile the code without my changes

../Include/XnMath.h: In instantiation of ‘XnBool xnl::Math::IsZero(T, T) [with T = float; XnBool = int]’:
../Include/XnVector3D.h:287:34:   required from here
../Include/XnMath.h:35:24: error: ‘Abs’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]

/usr/bin/ld: ../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release/libXnLib.a(XnLinuxMutex.o): undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_mutexattr_settype@@GLIBC_2.2.5' is defined in DSO /usr/lib/libpthread.so.0 so try adding it to the linker command line
/usr/lib/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status

Turns out you don't need to add librt to the linker flags anymore, but the other two changes (adding -pthread to linker flags and putting Abs definition first) are necessary to get it to compile and link properly.

tomoto commented 11 years ago

I found the first problem (order of Abs and IsZero) is already fixed in the develop branch: f95a9438fafbb944ec243353cd1ecf3b41b4b838

zhemao commented 11 years ago

OK, these fixes seem to have been made in the develop branch. The develop branch compiles correctly for me.

tomoto commented 11 years ago

Great to hear that your second problem has also gone. I was searching around but did not get any clues (because it was fixed, haha).

killkrt commented 11 years ago

Hi,

I got same problem reported by @zhemao. I get this error while I'm building the develop branch:

/usr/bin/ld: ../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release/libXnLib.a(XnLinuxMutex.o): undefined reference to symbol 'pthread_mutexattr_settype@@GLIBC_2.2.5' /usr/bin/ld: note: 'pthread_mutexattr_settype@@GLIBC_2.2.5' is defined in DSO /lib/x86_64-linux-gnu/libpthread.so.0 so try adding it to the linker command line /lib/x86_64-linux-gnu/libpthread.so.0: could not read symbols: Invalid operation collect2: error: ld returned 1 exit status

Could you help me?

Thank you.

These are the information about my system:

DISTRIB_ID=Ubuntu DISTRIB_RELEASE=13.04 DISTRIB_CODENAME=raring DISTRIB_DESCRIPTION="Ubuntu 13.04" NAME="Ubuntu" VERSION="13.04, Raring Ringtail" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 13.04" VERSION_ID="13.04" HOME_URL="http://www.ubuntu.com/" SUPPORT_URL="http://help.ubuntu.com/" BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)

EskenderTamrat commented 10 years ago

I had that problem previously, but following the commits, it was worked fine until the next Make error message I got when trying to build OpenNI 2 with the "sudo make" command.

g++ -o ../../../Bin/x64-Release/NiViewer ./../../../Bin/Intermediate/x64-Release/NiViewer/Device.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Draw.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Keyboard.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Menu.o ./../../../Bin/Intermediate/x64-Release/NiViewer/MouseInput.o ./../../../Bin/Intermediate/x64-Release/NiViewer/NiViewer.o ./../../../Bin/Intermediate/x64-Release/NiViewer/Capture.o -pthread -L../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release -L../../../Bin/x64-Release -lglut -lGL -lOpenNI2 -lXnLib -Wl,-rpath ./ ../../../ThirdParty/PSCommon/XnLib/Bin/x64-Release/libXnLib.a(XnLinuxTime.o):XnLinuxTime.cpp:function xnOSGetMonoTime: error: undefined reference to 'clock_gettime' collect2: error: ld returned 1 exit status make[1]: * [../../../Bin/x64-Release/NiViewer] Error 1 make[1]: Leaving directory `/home/opencog/Kinect/OpenNI2-FreenectDriver-a53bc59ee72a2ae19226ecdc6549cce895f11b46/Source/Tools/NiViewer' make: * [Source/Tools/NiViewer] Error 2

Any idea how to fix this problem? I'm running in Ubuntu 12.04 machine. Thanks!!!

nh2 commented 10 years ago

@EskenderTamrat Do you still get this error? I can build it fine on the develop branch (on Ubuntu 13.04 and 13.10).