Rack: Ubuntu: make dep fails: -fPIC needed

Created on 4 Apr 2018  路  10Comments  路  Source: VCVRack/Rack

Source revision: d2d4ee99d4a8c28f8d9fe83b19aca6f133f5c43d

On Ubuntu 16.04 make dep fails for glew with the following error:

cc -shared -Wl,-soname=libGLEW.so.2.1 -o lib/libGLEW.so.2.1.0 tmp/linux/default/shared/glew.o  -lGL -lX11                                                                                                                                                                          
/usr/bin/ld: tmp/linux/default/shared/glew.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC                                                                                                                    tmp/linux/default/shared/glew.o: error adding symbols: Bad value                                                                                                                                                                                                                   
collect2: error: ld returned 1 exit status                                                                                                                                                                                                                                          

Adding -fPIC to the CFLAGS for glew resolves that problem.

Most helpful comment

EDIT: ignore the below - I do see this problem, once I build against the 0.6 branch after the commit referenced by cschol!


I don't see this problem on Ubuntu 16.04 (well, kubuntu)

If you look at in dep/glew-2.1.0/Makefile you can see it is using this command:

config/config.guess | cut -d - -f 3 | sed -e 's/[0-9\.]//g;'

to set the $SYSTEM variable, and then will include one of the Makefiles in the config dir based on the value of $SYSTEM.

On my machine:

glew-2.1.0$ config/config.guess | cut -d - -f 3 | sed -e 's/[0-9\.]//g;'
linux
glew-2.1.0$

So config/Makefile.linux gets included, which contains CFLAGS.EXTRA += -fPIC

I'd suggest running the config.guess command as above, to see which value is given to $SYSTEM in your case(s). Maybe one of the following Makefiles, which don't set -fPIC, is being included?

glew-2.1.0$ grep -L fPIC config/Makefile.*
config/Makefile.cygming
config/Makefile.cygwin
config/Makefile.fedora-mingw32
config/Makefile.haiku
config/Makefile.irix
config/Makefile.linux-clang-egl
config/Makefile.linux-egl
config/Makefile.linux-mingw32
config/Makefile.linux-mingw64
config/Makefile.linux-mingw-w64
config/Makefile.linux-osmesa
config/Makefile.mingw
config/Makefile.mingw-win32
config/Makefile.msys
config/Makefile.msys-win32
config/Makefile.msys-win64
config/Makefile.openbsd
config/Makefile.solaris
glew-2.1.0$

All 10 comments

I'm getting the same thing on v0.6 right now. did a complete rm -rf on everything, cloned from scratch, got that error. On Ubuntu.

EDIT: ignore the below - I do see this problem, once I build against the 0.6 branch after the commit referenced by cschol!


I don't see this problem on Ubuntu 16.04 (well, kubuntu)

If you look at in dep/glew-2.1.0/Makefile you can see it is using this command:

config/config.guess | cut -d - -f 3 | sed -e 's/[0-9\.]//g;'

to set the $SYSTEM variable, and then will include one of the Makefiles in the config dir based on the value of $SYSTEM.

On my machine:

glew-2.1.0$ config/config.guess | cut -d - -f 3 | sed -e 's/[0-9\.]//g;'
linux
glew-2.1.0$

So config/Makefile.linux gets included, which contains CFLAGS.EXTRA += -fPIC

I'd suggest running the config.guess command as above, to see which value is given to $SYSTEM in your case(s). Maybe one of the following Makefiles, which don't set -fPIC, is being included?

glew-2.1.0$ grep -L fPIC config/Makefile.*
config/Makefile.cygming
config/Makefile.cygwin
config/Makefile.fedora-mingw32
config/Makefile.haiku
config/Makefile.irix
config/Makefile.linux-clang-egl
config/Makefile.linux-egl
config/Makefile.linux-mingw32
config/Makefile.linux-mingw64
config/Makefile.linux-mingw-w64
config/Makefile.linux-osmesa
config/Makefile.mingw
config/Makefile.mingw-win32
config/Makefile.msys
config/Makefile.msys-win32
config/Makefile.msys-win64
config/Makefile.openbsd
config/Makefile.solaris
glew-2.1.0$

Could someone chime in here? We have two people who can't build v0.6 on Linux due to this -fPIC issue. I tried adding -fPIC myself, but that just caused other errors.

I tried this:

$(glew):
    $(WGET) https://github.com/nigels-com/glew/releases/download/glew-2.1.0/glew-2.1.0.tgz
    $(UNTAR) glew-2.1.0.tgz
    $(MAKE) -C glew-2.1.0 CFLAGS.EXTRA="$(CFLAGS)" -fPIC LDFLAGS.EXTRA="$(LDFLAGS)" GLEW_DEST="$(realpath $(DEP_LOCAL))" LIBDIR="$(realpath $(DEP_LOCAL))/lib" install

And got this:

make -C glew-2.1.0 CFLAGS.EXTRA="-g -O3 -march=nocona" -fPIC LDFLAGS.EXTRA="" GLEW_DEST="/home/bruce/Rack/dep" LIBDIR="/home/bruce/Rack/dep/lib" install
make[2]: Entering directory '/home/bruce/Rack/dep/glew-2.1.0'
make[2]: PIC: No such file or directory
make[2]: *** No rule to make target 'PIC'.  Stop.

Is there a work around for this issue? Does it only affect a small number of people?

i just rolled back a few commits with my rack-repo (tag v0.6.0)...
building with the SDK also gives binaries that work with the current official rack.

Yeah, v0.6.0 works fine for me on all platforms. I'll stick with that for now. tx.

could someone comment here? does v0.6 build for most people on ubuntu or similar? It seems to two of us here that the branch is broken. While sticking on v0.6.0 seems viable for quite a while, it makes me uneasy.

@squinkylabs doesn't build for me as well on ubuntu, see #909.

I am on Ubuntu 17.10, trying to build VCVRack as of:

c3e9957fdd69ac593bd65171fce199f1725cf3b0 commit refs/tags/v0.6.0

And getting the same result:

cc -shared -Wl,-soname=libGLEW.so.2.1 -o lib/libGLEW.so.2.1.0 tmp/linux/default/shared/glew.o -L/usr/X11R6/lib64 -L/usr/lib64 -lGL -lX11 
/usr/bin/ld: tmp/linux/default/shared/glew.o: relocation R_X86_64_PC32 against symbol __glewActiveTexture can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:122: recipe for target 'lib/libGLEW.so.2.1.0' failed
make[2]: *** [lib/libGLEW.so.2.1.0] Error 1
make[2]: Leaving directory '/home/seclorum/fun/VCVRack/Rack/dep/glew-2.1.0'

Fix, for me, was the following:

diff --git a/dep.mk b/dep.mk
index 13d93c0..0b5da92 100644
--- a/dep.mk
+++ b/dep.mk
@@ -9,6 +9,10 @@ ifeq ($(ARCH), mac)
        DEP_LDFLAGS += -mmacosx-version-min=10.7 -stdlib=libc++
 endif

+ifeq ($(ARCH), lin)
+       DEP_FLAGS += -fPIC
+endif
+
 DEP_CFLAGS += $(DEP_FLAGS)
 DEP_CXXFLAGS += $(DEP_FLAGS)

.. 'normal build instructions' are proceeding as usual .. not sure if this is worth a PR, maybe one of the devs can add this to dep.mk next time they're in there... ?

The -fPIC problem is fixed for me at a0990d6 and make dep completes successfully. However, make (i.e. make Rack) fails on the final g++ invocation with:

/usr/bin/ld: dep/lib/libglfw3.a(x11_window.c.o): undefined reference to symbol 'XConvertSelection'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libX11.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
compile.mk:52: recipe for target 'Rack' failed
make: *** [Rack] Error 1

After some experimentation, I found the following diff allows make to complete successfully (creating an executable that emits sound) on my system, I include it in case it contains useful information, but it's a product of trial and error rather than any informed solution:

diff --git a/Makefile b/Makefile
index 272073a..8113c4e 100644
--- a/Makefile
+++ b/Makefile
@@ -42,15 +42,19 @@ ifeq ($(ARCH), lin)
        SOURCES += dep/osdialog/osdialog_gtk2.c
        CFLAGS += $(shell pkg-config --cflags gtk+-2.0)
        LDFLAGS += -rdynamic \
-               -lpthread -lGL -ldl -lX11 -lasound -ljack \
+               -lpthread -lGL -ldl -lX11 \
                $(shell pkg-config --libs gtk+-2.0) \
                -Ldep/lib \
-               -Wl,-Bstatic -lglfw3 -lGLEW -ljansson -lspeexdsp -lzip -lz -lrtmidi -lrtaudio -lcurl -lssl -lcrypto \
-               -Wl,-Bdynamic
+               -Wl,-Bstatic \
+               $(shell pkg-config --static --libs glfw3 glew | perl -pe 's/-lGL //; s/-lm //g' ) \
+         -ljansson -lspeexdsp -lzip -lz -lrtmidi -lrtaudio -lcurl -lssl -lcrypto \
+               -Wl,-Bdynamic -lasound -ljack -lm
        TARGET := Rack
 endif

@ndrspcfd That undefined reference is tracked in issue #888.

I am closing this issue since make dep works now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndrewBelt picture AndrewBelt  路  7Comments

polyclash picture polyclash  路  3Comments

DomiKamu picture DomiKamu  路  6Comments

alectron picture alectron  路  6Comments

PixelBulb picture PixelBulb  路  4Comments