Linking to OpenGL libraries on Linux (NVidia optirun primus)

Report crashes, strange behaviour, or apparent bugs
Post Reply
dbworth
Posts: 4
Joined: 03 Jun 2013, 18:57

Linking to OpenGL libraries on Linux (NVidia optirun primus)

Post by dbworth »

Hi

There is a bug with the pre-compiled version of V-REP for Linux 32 and 64 bit.
It will only affect a small number of users and could potentially be fixed by compiling from source, so maybe you won't consider it a bug.

Various laptops come with a dual-mode graphics system called NVidia Optimus.
On Windows, the driver will seamlessly select either the low-power graphics adapter or the high-power 3D graphics adapter if required.
On Linux, the driver is not that advanced yet and requires manual selection of the required graphics adapter.

So typically you run a program like
# ./vrep.sh

But if you want to use the NVidia graphics adapter you must run
# optirun ./vrep.sh


I have tested this on Ubuntu 10.04.4 32-bit and 12.04.1 64-bit and the same behaviour occurs.
V-Rep throws this error when trying to execute it via optirun:

QGLContext::makeCurrent(): Cannot make invalid context current.


By enabling some debug messages using:

# export LIBGL_DEBUG=verbose

and again running:
# optirun ./vrep.sh

indicates that V-Rep is not loading because it is forcing to load libGL from /usr/lib/... instead of the NVidia version of the library in a different location, which optirun puts into LD_LIBRARY_PATH.


This thread describes a similar problem:
https://github.com/Bumblebee-Project/Bu ... issues/374
where the software program was compiled using rpath that overides the LD_LIBRARY_PATH, and thus the libraries required by optirun are ignored.

* Are you able to fix the linker settings in the pre-compiled Linux version please?

* Or can you give some recommendations on how to re-compile from source?

As a starting point, I followed the V-Rep manual and have tried to compile using the supplied v_rep.pro QT project on Ubuntu 12 64-bit.
It almost compiles, except I get an error:
'IDSN_INERTIA_FRAME' was not declared in this scope.

Grep'ing around for that name in all 4 source ZIP files it cannot be found.
* What am I doing wrong?


Also, two other users reported the same problem in:
viewtopic.php?f=5&t=227

Thank you.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Linking to OpenGL libraries on Linux (NVidia optirun pri

Post by coppelia »

Hello,

Thank you for mentionning this. There is actually a small bug in the vrep.sh file: the LD_LIBRARY_PATH gets truncated from its current values, instead of just appending another path to it.

About your compilation error: which file is generating that error? It must be v_rep/sourceCode/dialogs/qdlgshapedyn.cpp. That file contains the only reference to IDSN_INERTIA_FRAME, and it includes v_repStrings.h at the top of the file, which itself includes v_repStringTable.h, which contains the definition of IDSN_INERTIA_FRAME. The file v_rep/v_rep.pro has the include path instruction for the string tables (INCLUDEPATH += "sourceCode/strings"). It should be able to find the reference to IDSN_INERTIA_FRAME.

Cheers

dbworth
Posts: 4
Joined: 03 Jun 2013, 18:57

Re: Linking to OpenGL libraries on Linux (NVidia optirun pri

Post by dbworth »

Hi

Thanks for your quick reply.

* Would it be possible to update the Linux binary on the download site please?


Yes all that information is correct... but the #define is missing from v_repStringTable.h in the source download zip file.

Actually, I was able to proceed further adding the following 2 missing defines to v_repStringTable.h :
#define IDSN_INERTIA_FRAME "sometext"
#define IDSN_INERTIA_FRAME_RELATIVE_TO_WORLD "sometext"


Also I got various errors for:
'CSensingThreadPool' has not been declared

I had to add:
#include "sensingThreadPool.h"

to:
sourceCode/collisions/RegColl.cpp
sourceCode/distances/RegDist.cpp
sourceCode/3dObjects/proximitySensor.cpp



Now I'm getting an error about a header file from QScintilla.
Actually, I installed all the requirements listed on the "Compiling V-REP" webpage using the package manager for Ubuntu 12.
But it seems the packages for libqscintilla2-*** (which is version 2.6) don't include all the required headers, so I will have to try compiling QScintilla 2.7 manually...
Last edited by dbworth on 05 Jun 2013, 20:50, edited 1 time in total.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Linking to OpenGL libraries on Linux (NVidia optirun pri

Post by coppelia »

Hello,

You are right, there was a mix-up that happended at some stage. Here the missing defines:

Code: Select all

#define IDSN_INERTIA_FRAME "Inertia frame"
#define IDSN_INERTIA_FRAME_RELATIVE_TO_WORLD "The inertia frame is now expressed relative to the absolute reference frame. Clicking 'Apply to selection' will from now on apply the same absolute position/orientation of the inertia frames."
Also about the other error, just add #include "sensingThreadPool.h" at the top of the file. I guess you might find some other similar problems (e.g. same problem in file RegDist.cpp). Sorry about the trouble, we are working with several versions in parallel...

Cheers

dbworth
Posts: 4
Joined: 03 Jun 2013, 18:57

Re: Linking to OpenGL libraries on Linux (NVidia optirun pri

Post by dbworth »

Ok so to run V-REP on my system, I edited vrep.sh like so:

#LD_LIBRARY_PATH=$dirname # (don't need this line)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$dirname # change this line

So I can now run:
# optirun ./vrep.sh
or
#primusrun ./vrep.sh


Also, I was able to successfully compile V-REP.
I installed all the required packages from Ubuntu sources, but compiled QScintilla 2.7 manually.
Hower that still doesn't put the required header file in a useful location like /usr/include/
V-REP seems to rely on at least SciLexer.h, so I had to include the directory where that was extracted too /home/user/Downloads/QScintilla-gpl-2.7/
Perhaps this header file could just be included with V-REP ?

Thankyou for your help.


Also, I thought it would be helpful for other users to have a compilation guide for the recommended Linux platform:


How to compile V-REP on Ubuntu Precise 12.04.2 LTS 64-bit
--------------------------------------------------------------------------
Note this was actually done using LUbuntu 12.04.2, which is almost the same but with a low graphics desktop.


If you can, run V-REP once:
# ./vrep.sh

Check the About menu to see what version of Qt you have installed:

Code: Select all

V-Rep Edu v 3.0.3
QT v 4.8.1
bullet 2.78
ode 0.12
build apr 26 2013

Download fresh copy of V-REP EDU.
Download V-REP source, extract, and put "v_rep" directory into the "V-REP_PRO_EDU_V3_0_3_64_Linux" directory.


Check what version of Qt4 is available from Ubuntu repo:

Code: Select all

# sudo aptitude show libqt4-core
e.g. v4.8.1
which is what we want


Install dependencies:

Code: Select all

# sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui

# sudo apt-get install lua5.1 lua5.1-doc lua5.1-lgi lua5.1-lgi-dev lua5.1-policy lua5.1-policy-dev 

# sudo apt-get install liblua5.1-0 liblua5.1-0-dbg liblua5.1-0-dev liblua5.1-dev 

# sudo apt-get install libboost-all-dev

# sudo apt-get  install qtcreator qtcreator-dbg qtcreator-doc
(Don't install QSctintilla2 from repo, it doesn't include the header files we need)

Download QScintilla-gpl-2.7.1.tar.gz
from here
http://www.riverbankcomputing.com/softw ... a/download

Fix the directory permisions and compile:

Code: Select all

# chown -R username:username QScintilla-gpl-2.7.1/
# cd Qt4Qt5
# qmake qscintilla.pro
# make
# sudo make install

Check what version of Qt that QMake is using:

Code: Select all

# qmake -v
QMake version 2.01a
Using Qt version 4.8.1 in /usr/lib/x86_64-linux-gnu

which is what we want.



In the V-REP source directory, edit
v_rep.pro


Edit the Unix block to something like:

Code: Select all

unix:!macx {
	INCLUDEPATH += /usr/lib                               // Boost directory
	INCLUDEPATH += /usr/include/qt4                       // QScintilla "Qt4" directory
	INCLUDEPATH += /usr/include/qt4/Qsci                                   // QScintilla "include" directory
        INCLUDEPATH += /home/USERNAME/Downloads/QScintilla-gpl-2.7.1/include   // for SciLexer.h
        LIBS += /usr/lib/x86_64-linux-gnu/libqscintilla2.so                    // QScintilla2 library
	contains(QMAKE_HOST.arch, x86_64):{                          // 64 Bit
		INCLUDEPATH += /usr/include/lua5.1                   // lua5.1 64"include" folder**
		LIBS += -Llua5_1_4_Linux26g4_64_lib/ -llua5.1
		DEFINES += QT_VREP_64BIT
	}
	!contains(QMAKE_HOST.arch, x86_64):{                        // 32 Bit
		INCLUDEPATH += /usr/include/lua5.1                  // lua5.1 32"include" folder**
		LIBS += -Llua5_1_4_Linux26g4_lib/ -llua5.1
	}
	DEFINES += LIN_VREP
}


Also change these 3 lines, from the top one (incorrect) to the one below:

Code: Select all

	
#sourceCode/communication/serial_mac_linux.h \
sourceCode/communication/serialPort/serial_mac_linux.h \

#sourceCode/geometricAlgorithms/algos/MeshRoutines.h \
sourceCode/geometricAlgorithms/MeshRoutines.h \

#HEADERS += sourceCode/various/vrepConfig  \
HEADERS += sourceCode/various/vrepConfig.h  \

Make some corrections to the source code:

Edit this file:
v_rep/sourceCode/strings/v_repStringTable.h

add the following 2 lines:

Code: Select all

#define IDSN_INERTIA_FRAME "Inertia frame"
#define IDSN_INERTIA_FRAME_RELATIVE_TO_WORLD "The inertia frame is now expressed relative to the absolute reference frame. Clicking 'Apply to selection' will from now on apply the same absolute position/orientation of the inertia frames."
Edit these 3 files:
v_rep/sourceCode/collisions/RegColl.cpp
v_rep/sourceCode/distances/RegDist.cpp
v_rep/sourceCode/3dObjects/proximitySensor.cpp

add the following include:

Code: Select all

#include "sensingThreadPool.h"


Now compile V-REP:

Run QT4 Creator
and load the project file v_rep.pro from
V-REP_PRO_EDU_V3_0_3_64_Linux/v_rep/

or go to that same directory and run:

Code: Select all

# qmake v_rep.pro
# make
# sudo make install
Which should install /usr/lib/libv_rep.so***

.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: Linking to OpenGL libraries on Linux (NVidia optirun pri

Post by coppelia »

Thanks a lot for the very detailed instructions!
We'll try to include them for next release.

Cheers

Post Reply