LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2016, 11:13 PM   #1
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Rep: Reputation: 51
Difficulties installing a C++ library properly


I'm trying to install a development library called nanogui-sdl:
https://github.com/dalerank/nanogui-sdl
It is not available as a debian package, as far as I know. Here's what I'm trying so far:

Code:
cd /usr/local/lib
git clone --recursive https://github.com/dalerank/nanogui-sdl
cd nanogui-sdl
cmake ./
make
cd ..
ln -s nanogui-sdl/libnanogui.so libnanogui.so
ldconfig
It's "installed", so I'm going to try to compile the example that comes with the package. I'll note that the example is included as a cmake target, and there is a binary in /usr/local/lib/nanogui-sdl which runs beautifully. Like, really beautifully. Worth checking out if you ever use SDL.
Code:
cd ~/src
g++ example2.cpp -llibnanogui.so -I/usr/local/lib/nanogui-sdl

In file included from /usr/local/lib/nanogui-sdl/include/object.h:15:0,
                 from /usr/local/lib/nanogui-sdl/include/widget.h:15,
                 from /usr/local/lib/nanogui-sdl/include/screen.h:17,
                 from example2.cpp:14:
/usr/local/lib/nanogui-sdl/include/common.h:15:22: fatal error: Eigen/Core: No such file or directory
compilation terminated.
I'm guessing that I'm doing something totally wrong. I'm not used to cmake, or installing this sort of library without dpkg in general.

Last edited by crazy-yiuf; 07-14-2016 at 11:48 PM. Reason: formatting
 
Old 07-14-2016, 11:46 PM   #2
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
deleted post

Last edited by crazy-yiuf; 07-15-2016 at 12:09 AM.
 
Old 07-15-2016, 12:08 AM   #3
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
Edit: Now I'm getting it to compile with:
g++ example2.cpp -std=gnu++11 `sdl-config --cflags` -lSDL2 -lnanogui -I/usr/local/lib/nanogui-sdl -I/usr/include/eigen3

But ldd ./a.out gives:
...
libnanogui.so => not found
...

I'll try it again in the morning.

Last edited by crazy-yiuf; 07-15-2016 at 12:56 AM.
 
Old 07-15-2016, 02:23 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Try 'make install'
Code:
make
make install
ldconfig
Note: /usr/local/src would be more plausible location for the source.
 
1 members found this post helpful.
Old 07-15-2016, 07:20 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,513

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
fatal error: Eigen/Core: No such file or directory
# apt-get install libeigen3-dev

... provides /usr/include/eigen3/Eigen/Core : the file Core is a C header.

Either point to Eigen, like CFLAGS=-I/usr/include/eigen3/Eigen
or symlink Eigen to e.g. /usr/local/include/ :
# cd /usr/local/include/ && ln -s /usr/include/eigen3/Eigen


-
 
1 members found this post helpful.
Old 07-15-2016, 11:29 AM   #6
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
Success! I still suspect there was either a bug in the cmake stuff or something obvious I wasn't doing. But thanks for the tips everyone.

I'll try cleaning up the installation a bit now, but for future googlers the general steps were:
1. Install as per first post, but in the proper directory as NevemTeve said.
2. Fix file permissions and make sure ldconfig -v is finding the .so
3. Your compilation command might end up looking like this:
g++ example2.cpp -std=gnu++11 -I/usr/include/SDL -I/usr/local/lib/nanogui-sdl -I/usr/local/lib/nanogui-sdl/ext/eigen/ -D_GNU_SOURCE=1 -D_REENTRANT -lSDL2 -L/usr/local/lib -lnanogui

So it's a good idea to use a script or a makefile. My mistake was just not being thorough enough in tracking down all of the places I needed to include. Good learning experience, as always.

Last edited by crazy-yiuf; 07-15-2016 at 11:30 AM.
 
Old 07-15-2016, 12:54 PM   #7
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
I spoke too soon. The binary I compile only runs about one in every twenty times. The other 19/20 it segfaults. Gdb says:

Code:
(gdb) run
Starting program: /home/developer/src/sdlGame/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe9bd0700 (LWP 3738)]

Thread 1 "a.out" received signal SIGSEGV, Segmentation fault.
0x0000000500000068 in ?? ()
(gdb) backtrace
#0  0x0000000500000068 in ?? ()
#1  0x0000000000405e3f in std::_Function_base::~_Function_base (this=0x7fffffffdba0, 
    __in_chrg=<optimized out>) at /usr/include/c++/5/functional:1830
#2  0x0000000000406592 in std::function<void (int)>::~function() (this=0x7fffffffdba0, 
    __in_chrg=<optimized out>) at /usr/include/c++/5/functional:1974
#3  0x000000000040803c in std::function<void (int)>::operator=(std::function<void (int)> const&) (
    this=0xd34638, __x=...) at /usr/include/c++/5/functional:2071
#4  0x00000000004065c0 in nanogui::ComboBox::setCallback(std::function<void (int)> const&) (
    this=0xd344a0, callback=...) at /usr/local/lib/nanogui-sdl/include/combobox.h:36
#5  0x0000000000410a14 in nanogui::detail::FormWidget<test_enum, std::integral_constant<bool, true> >::setCallback(std::function<void (test_enum)> const&) (this=0xd344a0, cb=...)
    at /usr/local/lib/nanogui-sdl/include/formhelper.h:216
#6  0x000000000040c899 in nanogui::FormHelper::addVariable<test_enum>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::function<void (test_enum)> const&, std::function<test_enum ()> const&, bool) (this=0xd1d4c0, label="Enumeration", setter=..., getter=..., 
    editable=true) at /usr/local/lib/nanogui-sdl/include/formhelper.h:103
#7  0x0000000000408f49 in nanogui::FormHelper::addVariable<test_enum> (this=0xd1d4c0, 
    label="Enumeration", value=@0x629650: Item2, editable=true)
    at /usr/local/lib/nanogui-sdl/include/formhelper.h:125
#8  0x0000000000405114 in main () at example2.cpp:115
Which is very strange since the binary that running "make" created from the exact same source file runs every time. I compare the ldd output of the two, and they are loaded in a different order. Should that make a difference? If I sort the ldd output and compare the first 27 characters they are identical.

I guess I'll try reinstalling it a bit differently later, so I'll leave the thread marked as solved, but any thoughts are appreciated in the mean time. The contents of the nanogui directory are:

Code:
developer /usr/local/lib/nanogui-sdl $ ls
bin2c           cmake_install.cmake  example2  include        Makefile               README.md
CMakeCache.txt  CMakeLists.txt       ext       libnanogui.so  nanogui_resources.cpp  resources
CMakeFiles      example1             icons     LICENSE.txt    nanogui_resources.h    src
make install gives:
make: *** No rule to make target 'install'. Stop.

But it certainly feels like I'm missing some sort of install command. I'll be happy to post the contents any of these files on pastebin, but I can't make heads or tails of them.

I've tried a few more things and I'm stumped, so reopening question.

Last edited by crazy-yiuf; 07-15-2016 at 02:10 PM.
 
Old 07-15-2016, 01:49 PM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
I think the developer might have forgotten about the installation part, which usually comes between compilation and usage. That happens even to the best of programmers sometimes. You could file a bug-report/feature-request.

Edit:
Also libnanogui.so is created with no major/minor version numbers.

These bits wouldn't matter in Windows, but as it is Unix, I suggest non-using this (otherwise brilliant) product for now.

Last edited by NevemTeve; 07-15-2016 at 01:56 PM.
 
1 members found this post helpful.
Old 07-15-2016, 02:15 PM   #9
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
Haha, yes, I suspect you're right, though I've seen at least one case of it working on Linux.

Earlier I tried making up some major and minor versions with no luck. I'll pester the dev when I get a chance.
 
Old 07-15-2016, 03:13 PM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,871
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
Note1: there's two other useful unix-tools that could be suggested to the author: libtool and pkg-config
Note2: most likely your problem could be easily debugged, if it weren't in C++. The awesome features of C++ like templates and overloading makes it hard to debug.
 
1 members found this post helpful.
Old 07-15-2016, 06:53 PM   #11
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
It occurred to me that I probably should have tried Valgrind before now. It works perfectly when it's running in Valgrind! Here's the basic output
http://paste.debian.net/781864/

and the -v --track-origins output:
http://paste.debian.net/781865/

I linked this thread in my issue report, so I'll note here that I'm using ratpoison as a window manager and the SDL window doesn't automatically full screen (which is fine, I just don't know if it could be related somehow).

Edit: those were for example2.cpp. Example1 still dies in Valgrind and outputs "killed":
http://paste.debian.net/781867/

Edit: the tried and true "add a ton of cout" debugger indicates the problem starts with this line in example2
ref<Window> rwindow = gui->addWindow(Eigen::Vector2i(10, 10), "Form helper example");

Last edited by crazy-yiuf; 07-15-2016 at 07:27 PM.
 
Old 07-15-2016, 09:54 PM   #12
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
First a question. Did you perform a debug build of the library? I ask because of the "optimized out" in the backtrace.
Code:
cmake -DCMAKE_BUILD_TYPE=DEBUG ..
Looking through the CMakeLists.txt file in the root directory of that library, I noticed the following:
Code:
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  # Enable C++11 mode on GCC / Clang
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  add_definitions( -DEIGEN_DONT_ALIGN )
endif()
You might try adding -DEIGEN_DONT_ALIGN to your command line.
 
1 members found this post helpful.
Old 07-16-2016, 07:42 AM   #13
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,784

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by norobro View Post
First a question. Did you perform a debug build of the library? I ask because of the "optimized out" in the backtrace.
Also, with debugging info, the valgrind errors should have line numbers which makes them much more useful.
 
1 members found this post helpful.
Old 07-16-2016, 11:58 AM   #14
crazy-yiuf
Member
 
Registered: Nov 2015
Distribution: Debian Sid
Posts: 119

Original Poster
Rep: Reputation: 51
Quote:
Did you perform a debug build of the library? I ask because of the "optimized out" in the backtrace
I did not, it looks like I have a lot to learn about cmake. Simply running the code after following your instructions explained the problem clearly, I think:

Code:
a.out: /usr/local/src/nanogui-sdl/ext/eigen/Eigen/src/Core/DenseStorage.h:86: Eigen::internal::plain_array<T, Size, MatrixOrArrayOptions, 16>::plain_array() [with T = float; int Size = 4; int MatrixOrArrayOptions = 0]: Assertion `(reinterpret_cast<size_t>(eigen_unaligned_array_assert_workaround_gcc47(array)) & 0xf) == 0 && "this assertion is explained here: " "http://eigen.tuxfamily.org/dox-devel/group__TopicUnalignedArrayAssert.html" " **** READ THIS WEB PAGE !!! ****"' failed.
Aborted
And -DEIGEN_DONT_ALIGN fixed it! Brilliant. I'll suggest adding it to the github readme. Thank you everyone, now I can start on my project

To put it in a fool-proof summary, this should basically work:
su
apt-get install cmake xorg-dev libglu1-mesa-dev libsdl2.0
cd /usr/local/src
git clone --recursive https://github.com/dalerank/nanogui-sdl
cd nanogui-sdl
cmake ./
make
cp src/example2.cpp ./
g++ example2.cpp -std=gnu++11 `sdl2-config --cflags --libs` -I/usr/local/src/nanogui-sdl -I/usr/local/src/nanogui-sdl/ext/eigen/ -DEIGEN_DONT_ALIGN -L/usr/local/src/nanogui-sdl -lnanogui
export LD_LIBRARY_PATH=/usr/local/src
./a.out

Cleaning it up and compiling from your home directory is left as an exercise for the reader.

Last edited by crazy-yiuf; 07-16-2016 at 01:58 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
difficulties for installing gnuplot gnugpl Linux - Newbie 9 07-19-2012 02:01 PM
Difficulties installing new urpmi destinations iqbala Mandriva 1 10-23-2005 04:36 PM
Difficulties Compiling and Installing GNUstep linguae Linux - Software 0 07-23-2004 02:58 PM
Installing xine w/rh9--difficulties masa4i89 Linux - Newbie 3 01-30-2004 10:17 AM
Difficulties installing Netscape 7.1 saxophobe Linux - Newbie 4 09-23-2003 09:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration