[SOLVED] Difficulties installing a C++ library properly
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,513
Rep:
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
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.
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:
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.
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.
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.
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/
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: 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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.