Bug 223518

Summary: [PATCH] editors/emacs: /usr/bin/ld: cannot find -lomp
Product: Ports & Packages Reporter: Kalten <kalten>
Component: Individual Port(s)Assignee: Ashish SHUKLA <ashish>
Status: Closed FIXED    
Severity: Affects Only Me Keywords: patch
Priority: --- Flags: bugzilla: maintainer-feedback? (ashish)
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
editors/emacs: link-error openmp patch [1]
none
log: prior to patch: link-error
none
log: poudriere testport -P output [1]
none
editors/emacs: link-error openmp patch [v2]
none
log: poudriere testport -P output [v2] none

Description Kalten 2017-11-08 10:22:12 UTC
Created attachment 187845 [details]
editors/emacs: link-error openmp patch [1]

Greetings!

Iff compiling editors/emacs with the following options under poudriere
> ---Begin OPTIONS List---
> ===> The following configuration options are available for emacs25-25.3_1,3:
>      ACL=on: Access control list support
>      CANNA=off: Japanese input support
>      DBUS=on: D-Bus IPC system support
>      GNUTLS=on: SSL/TLS support via GnuTLS
>      LLDB=off: LLDB support for GUD
>      MODULES=on: Dynamic modules support
>      SOURCES=on: Install sources
>      X11=on: X window system support
>      XML=on: XML format or parser support
> ====> Graphics support (each implies X11)
>      CAIRO=off: Experimental Cairo library support     (implies PNG, XFT)
>      GIF=on: GIF image format support
>      JPEG=on: JPEG image format support
>      MAGICK=on: ImageMagick image processing support
>      PNG=on: PNG image format support
>      SVG=on: Scalable vector graphics support       (implies PNG)
>      TIFF=on: TIFF image format support
>      XPM=on: XPM pixmap image format support
> ====> Other X11-dependent (each implies X11)
>      GCONF=on: GConf configuration backend support
>      GSETTINGS=on: GSettings API for application settings
>      M17N=on: M17N for text-shaping                  (implies XFT)
>      OTF=on: Opentype fonts                         (implies XFT)
>      SCROLLBARS=on: Toolkit scroll-bars
>      XFT=on: Xft font library support
>      XIM=on: X Input Method
>      XWIDGETS=off: GTK widgets in Emacs buffers           (requires GTK3)
> ====> File notification support: you can only select none or one of them
>      GFILE=off: File notification via gfile
>      KQUEUE=on: File notification via kqueue
> ====> Sound (audio) support: you can only select none or one of them
>      ALSA=off: ALSA audio architecture support
>      OSS=on: Open Sound System support
> ====> X11 toolkit (each implies X11): you can only select none or one of them
>      GTK2=off: GTK+ 2 GUI toolkit support
>      GTK3=on: GTK+ 3 GUI toolkit support
>      MOTIF=off: Motif widget library support
>      XAW=off: Athena widgets
>      XAW3D=off: Athena3D widgets
> ===> Use 'make config' to modify these settings
> ---End OPTIONS List---

compilation fails on my machine with the error:
...8<---
> gmake[3]: Leaving directory '/wrkdirs/usr/ports/editors/emacs/work/emacs-25.3/admin/unidata'
> cc -Demacs  -I. -I. -I../lib -I../lib   -I/usr/local/include -I/usr/local/include/gtk-3.0 -I/usr/local/include/pango-1.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/local/include/cairo -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/libdrm -I/usr/local/include/libpng16 -I/usr/local/include/harfbuzz -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/gio-unix-2.0/ -I/usr/local/include/atk-1.0 -D_THREAD_SAFE -I/usr/local/include/at-spi2-atk/2.0 -I/usr/local/include/at-spi-2.0 -I/usr/local/include/dbus-1.0 -I/usr/local/lib/dbus-1.0/include -pthread  -I/usr/local/include -D_THREAD_SAFE -pthread -I/usr/local/include/freetype2    -I/usr/local/include/librsvg-2.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/libpng16 -I/usr/local/include/cairo -I/usr/local/include/pixman-1 -I/usr/local/include/freetype2 -I/usr/local/include/libdrm -D_THREAD_SAFE -pthread  -I/usr/local/include/ImageMagick-6 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16  -I/usr/local/include/libpng16 -I/usr/local/include/libxml2  -I/usr/local/include/dbus-1.0 -I/usr/local/lib/dbus-1.0/include  -I/usr/local/include -D_THREAD_SAFE -pthread  -I/usr/local/include -D_THREAD_SAFE -pthread  -I/usr/local/include -D_THREAD_SAFE -pthread   -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -pthread  -I/usr/local/include/gconf/2 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include -I/usr/local/include/orbit-2.0 -DORBIT2=1 -pthread  -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include  -I/usr/local/include/freetype2  -I/usr/local/include -I/usr/local/include/freetype2  -I/usr/local/include/freetype2 -I/usr/local/include  -I/usr/local/include  -MMD -MF deps/.d -MP -I/usr/local/include -I/usr/local/include/p11-kit-1    -Wno-switch -Wno-tautological-constant-out-of-range-compare -Wno-pointer-sign -Wno-string-plus-int -Wno-unknown-attributes  -O2 -pipe  -fstack-protector -fno-strict-aliasing  -Wl,-znocombreloc  -fstack-protector -L/usr/local/lib \
>   -o temacs  vm-limit.o dispnew.o frame.o scroll.o xdisp.o menu.o xmenu.o window.o charset.o coding.o category.o ccl.o character.o chartab.o bidi.o cm.o term.o terminal.o xfaces.o xterm.o xfns.o xselect.o xrdb.o xsmfns.o xsettings.o gtkutil.o emacsgtkfixed.o dbusbind.o emacs.o keyboard.o macros.o keymap.o sysdep.o buffer.o filelock.o insdel.o marker.o minibuf.o fileio.o dired.o cmds.o casetab.o casefiddle.o indent.o search.o regex.o undo.o alloc.o data.o doc.o editfns.o callint.o eval.o floatfns.o fns.o font.o print.o lread.o dynlib.o emacs-module.o syntax.o unexelf.o bytecode.o process.o gnutls.o callproc.o region-cache.o sound.o atimer.o doprnt.o intervals.o textprop.o composite.o xml.o kqueue.o  profiler.o decompress.o     xfont.o ftfont.o xftfont.o ftxfont.o  fontset.o fringe.o image.o xgselect.o  terminfo.o lastfile.o gmalloc.o     ../lib/libgnu.a       -ltiff -ljpeg -lpng16 -lgif -lXpm -L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lpthread -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl  -lSM -lICE -lX11 -lX11-xcb -lxcb -lXrender -L/usr/local/lib -lXft   -L/usr/local/lib -lrsvg-2 -lm -lgio-2.0 -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lcairo -lpthread  -L/usr/local/lib -lMagickWand-6 -lMagickCore-6       -lrt -L/usr/local/lib -ldbus-1  -lexecinfo -L/usr/local/lib -lXrandr  -L/usr/local/lib -lXinerama  -L/usr/local/lib -lXfixes  -L/usr/local/lib -lxml2    -lutil  -lncurses  -L/usr/local/lib -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl  -L/usr/local/lib -lgconf-2 -lglib-2.0 -lintl  -L/usr/local/lib -lgobject-2.0 -lglib-2.0 -lintl   -L/usr/local/lib -lfreetype  -L/usr/local/lib -lfontconfig -lfreetype  -L/usr/local/lib -lotf -lfreetype  -L/usr/local/lib -lm17n-flt -lm17n-core  -L/usr/local/lib -lgnutls  -lpthread  -lm -lz 
> /usr/bin/ld: cannot find -lomp
> cc: error: linker command failed with exit code 1 (use -v to see invocation)
> gmake[2]: *** [Makefile:596: temacs] Error 1
--->8...

It seems to be necessary to add ‘compiler:openmp’ to the ‘USES’ variable in
the Makefile of the emacs port. I am not sure whether it is the correct
way of solving this. (see patch file)

Iff I am not mistaken, it does use gcc6 instead of clang after this change.

I think it may have to do with ImageMagick.

The ports multimedia/transcode and multimedia/libxine might suffer from the
same problem—I have not looked into the matter yet.

Regards,
 Kalten
Comment 1 Kalten 2017-11-08 10:27:11 UTC
Created attachment 187846 [details]
log: prior to patch: link-error

The log with the link-error (prior to the patch)
Note: clang is used.
Comment 2 Kalten 2017-11-08 10:29:20 UTC
Created attachment 187847 [details]
log: poudriere testport -P output [1]

Note: now gcc6 is used
Comment 3 Ashish SHUKLA freebsd_committer 2017-11-09 00:02:10 UTC
(In reply to Kalten from comment #0)

[...]

> It seems to be necessary to add ‘compiler:openmp’ to the ‘USES’ variable in
the Makefile of the emacs port. I am not sure whether it is the correct
way of solving this. (see patch file)

> Iff I am not mistaken, it does use gcc6 instead of clang after this change.

> I think it may have to do with ImageMagick.

This indeed has to do with ImageMagick, as when ImageMagick is built with OPENMP option, then you're expected to link dependent ports with -lomp too. If you recompile ImageMagick without OPENMP option, then this error should go away.

Your diff is okay, for when ImageMagick is built with OPENMP option, which is not always the case.

I will check with ImageMagick maintainer to see if we there is now a possible workaround for these cases, and get back to you.

Thanks!
Comment 4 Kalten 2017-11-09 01:14:37 UTC
(In reply to Ashish SHUKLA from comment #3)

> I will check with ImageMagick maintainer to see if we there is now
> a possible workaround for these cases, and get back to you.
Hmmm…
‘/usr/local/bin/GraphicsMagick-config --libs’
from graphics/GraphicsMagick tells us ‘-lgomp’.
It may help, although it is not graphics/ImageMagick

Regards,
 Kalten
Comment 5 Kalten 2017-11-09 14:05:09 UTC
(In reply to Ashish SHUKLA from comment #3)
> I will check with ImageMagick maintainer to see if we there is now
> a possible workaround for these cases, and get back to you.
I am sorry: my approach in comment #4 was nonsense.
You can use ‘/usr/local/bin/Magick-config --cflags’ or
‘/usr/local/bin/Magick-config --cppflags’ to get lines like
> -I/usr/local/include/ImageMagick-6 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 
showing you, that ImageMagick has been compiled with ‘openmp’.

Regards,
 Kalten
Comment 6 Ashish SHUKLA freebsd_committer 2017-11-10 10:19:08 UTC
(In reply to Kalten from comment #5)

Thanks for the confirmation. I talked to ImageMagick maintainer, but unfortunately we don't have a good fix for this right now, as it's a bit complicated atm.

The patch you have provided will enable OpenMP enabled compiler for default Emacs build, which is an unnecessary dependency, esp. if ImageMagick is not built with OPENMP, or not using ImageMagick.

Possible workaround is don't install ImageMagick with OPENMP enabled, or disable IMAGEMAGICK option in Emacs. In editors/emacs-devel, instead of failing the build, it skips ImageMagick option in this situation[1]

[1] https://people.freebsd.org/~ashish/emacs-devel-27.0.50.20171109,2.log
Comment 7 Kalten 2017-11-17 23:41:06 UTC
Created attachment 188085 [details]
editors/emacs: link-error openmp patch [v2]

Greetings!

(In reply to Ashish SHUKLA from comment #6)
> […] I talked to ImageMagick maintainer, but unfortunately we don't
> have a good fix for this right now, as it's a bit complicated atm.
Well: how about this new patch [v2]

The package of graphics/ImageMagick has to be installed already, so this
mechanism could be useful in general (the first part might even be moved
to somewhere in /usr/ports/Mk/)

> The patch [v1] (attachment 187521 [details]) you have provided will enable
> OpenMP enabled compiler for default Emacs build, which is an
> unnecessary dependency, esp. if ImageMagick is not built with OPENMP,
> or not using ImageMagick.
You are right about the old patch [v1] (attachment 187521 [details]).
Hence now the new one [v2]. What do you think?

> Possible workaround is don't install ImageMagick with OPENMP enabled,
> or disable IMAGEMAGICK option in Emacs. […]
In my opinion not a clean solution. My new patch [v2] might be better?

Regards,
 Kalten.
Comment 8 Kalten 2017-11-17 23:47:42 UTC
(In reply to Kalten from comment #7)
I am sorry about a small error in my mail (not the patch).

The old patch [v1] was not attachment 187521 [details], but attachment 187845 [details].

BTW: The new patch [v2] is attachment 188085 [details].

Sorry, once again!
 Kalten
Comment 9 Kalten 2017-11-17 23:52:49 UTC
Created attachment 188087 [details]
log: poudriere testport -P output [v2]
Comment 10 Ashish SHUKLA freebsd_committer 2017-11-18 05:20:49 UTC
(In reply to Kalten from comment #7)

attachment 188085 [details] looks good, and doesn't seem to break INDEX when .pc file is missing. I'm trying it on ports editors/emacs{,-devel}, and let you know how it goes.

Thank you for working on it.
Comment 11 commit-hook freebsd_committer 2017-11-19 09:14:23 UTC
A commit references this bug:

Author: ashish
Date: Sun Nov 19 09:13:44 UTC 2017
New revision: 454482
URL: https://svnweb.freebsd.org/changeset/ports/454482

Log:
  - Fix broken behaviour when port is compiled with IMAGEMAGICK option
    and ImageMagick is built with OPENMP option

  PR:		223518
  Submitted by:	Kalten <kalten@gmx.at>

Changes:
  head/editors/emacs/Makefile
Comment 12 Ashish SHUKLA freebsd_committer 2017-11-19 09:16:32 UTC
Thanks, committed in ports r454482 and ports r454481.