Is it possible to recompile GLFW3

It appears that during the Jetpack installation process, libglfw3 is cross-compiled (into a static lib) and copied over to the Visionworks Samples directory (~ubuntu/VisionWorks-1.4-Samples/3rdparty/glfw3/libs) on the TX1. This is fine when trying to statically link executables, etc. However, I’m developing a shared library (.so). When linking the object files to create the .so, the linker complains when trying to link in the static libglfw3.a as it was not compiled with -fPIC:

/usr/bin/ld: /home/ubuntu/VisionWorks-1.4-Samples/3rdparty/glfw3/libs/libglfw3.a(init.c.o)(.text+0x18): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `__stack_chk_guard@@GLIBC_2.17'
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status

I tried downloading the latest GLFW3 release, compiling and installing it as a shared lib on the Jetson (all of which worked), but when my application runs, it segfaults upon trying to create a renderer - presumably wrong GLFW3 version or there is something special with the Nvidia version??

Is there a way to recompile libglfw3 that comes with Jetpack using -fPIC? I can’t seem to find the sources anywhere! (In a related note, libnvxio.a also needs to be recompiled with -fPIC, but the sources are all there, so this is just a matter of changing the Makefile.)

If you run “ldd ” you should see what libraries the executable expects to find for linking. From this you can determine what is missing or mismatched. On the Jetson you can run “sudo ldconfig -p” to print what the linker sees as available.

Note that when cross compiling user space applications any need to link to outside libraries means that not only do you need the cross tool chain, you also need the cross binutils and a sysroot matching your destination environment (I tend to use a loopback mounted clone of the Jetson for actual environment, but Linaro also provides those environments…on the other hand, if you need some special library such as glfw, the Linaro version won’t include this…thus the clone from a Jetson that had this installed is a better choice). In the case of -fPIC you are working with relocatable code, which in turn implies the use of cross binutils is required.

Cross environment setup is not so bad with just a kernel compile, it gets complicated when user space is added. It may be that you would more easily accomplish the build natively on a Jetson (the only time a Jetson native build is more difficult than cross compile is when multiple architectures are required simultaneously).

@linuxdev: I am compiling natively on the Jetson. The issue is that libglfw3.a that is included with the Jetpack install is not compiled with -fPIC. I was assuming it was cross-compiled during Jetpack installation of the rootfs on the Jetson, but I could be completely off in that assumption. For all I know, it could have been pre-compiled by nvidia and just copied during the install process.

I suppose the real question is: is there any way of getting/producing a version of libglfw3.a that has been (or can be) compiled with -fPIC.

Ahh, I see…yes the “.a” static libs would not have that.

I have most repositories uncommented for the apt package manager. When I run “apt search glfw” it shows several related packages. The one you want would be “libglfw3-dev” (installing the dev package via “sudo apt-get install libglfw3-dev” should result in the library itself also being installed, which is libglfw3). This should probably do the job. To verify run “sudo ldconfig -p | grep glfw”.

Hrm, unfortunately that doesn’t seem to exist for Ubuntu 14.04. Looks like I might need to install Jetpack 2.3 / L4T 24.2 so that I can get to 16.04. Will try tomorrow and update with any progress.

Have you uncommented the alternate repositories in “/etc/apt/sources.list”? And of course if you do change something (or for that matter just want recent listings) be sure to first run “sudo apt update” prior to the “apt-get” or “apt search”. Admittedly, I found this under Ubuntu 16.04 (L4T R24.2), but glfw has been out for quite some time. “apt search glfw” should show at least something under Ubuntu 14.04. On the other hand, R24.2 seems to be a significant improvement over earlier releases…I’d recommend this upgrade anyway if you don’t have a reason to stick to older versions.

Indeed, upgrading to R24.2 seems to have solved this issue (and potentially caused others) as libnvxio is now a shared object rather than a static lib and doesn’t directly reference the libglfw.a provided with the samples. So now just doing -lnvxio when creating my shared object works just as expected. Thanks much for the help!