sionescu / iolib

Common Lisp I/O library
http://common-lisp.net/project/iolib/
MIT License
141 stars 31 forks source link

fix include flags #62

Closed omar-polo closed 2 years ago

omar-polo commented 3 years ago

First, let me apologize for my ignorance. I'm still pretty new to common lisp and I have limited knowledge on how cffi works, and how iolib uses cffi.

I wasn't able to install iolib with quicklisp because the compilation of the c files failed: it couldn't include the libfixposix headers. The thing is that I have libfixposix installed, but its headers are in /usr/local/include and not /usr/include. Some unices put thirdy party stuff in /usr/local, and that was my case.

I got iolib compiling with an hackish

(ql:quickload :cffi)
(push "-I/usr/local/include" cffi-toolchain:*cc-flags*)

before (ql:quickload :iolib).

From the documentation of cffi I can see it supports taking the cflags from pkg-config, but I'm not sure how to do it.

sionescu commented 3 years ago

What OS are you using ?

omar-polo commented 3 years ago

I use OpenBSD, but it's not the only OS that install packages files in places other than /usr/{include,lib}; FreeBSD also do this, and NetBSD use /usr/pkg/{include,lib} IIRC.

sionescu commented 3 years ago

It seems very strange to me that /usr/local/include is not already in the default include list of the compiler. Can you investigate what's happening ?

omar-polo commented 3 years ago

I rebuild libfixposix just to be sure (I'm running libfixposix-0.4.3 freshly build), and when I try to (ql:quickload :iolib) I get the following error:

Subprocess #<UIOP/LAUNCH-PROGRAM::PROCESS-INFO {1004166023}>
 with command ("cc" "-o"
               "/home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel-tmp9DT7SEFG.o"
               "-c" "-O2" "-pipe" "-Wall" "-Wundef"
               "-Wsign-compare" "-Wpointer-arith"
               "-fno-omit-frame-pointer" "-pthread" "-fno-pie"
               "-fPIC"
               "-I/home/op/quicklisp/dists/quicklisp/software/cffi_0.23.0/"
               "/home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel.c")
 exited with error code 1
   [Condition of type CFFI-GROVEL:GROVEL-ERROR]

Backtrace:
 0: (CFFI-GROVEL:GROVEL-ERROR "~a" #<UIOP/RUN-PROGRAM:SUBPROCESS-ERROR {100416A083}>)
 1: ((FLET "THUNK" :IN CFFI-GROVEL:PROCESS-GROVEL-FILE))
 2: (SB-IMPL::%WITH-STANDARD-IO-SYNTAX #<FUNCTION (FLET "THUNK" :IN CFFI-GROVEL:PROCESS-GROVEL-FILE) {2E1775DCB}>)
 3: (CFFI-GROVEL:PROCESS-GROVEL-FILE #P"/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix.lisp" #P"/home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects..
 4: ((:METHOD ASDF/ACTION:PERFORM (CFFI-GROVEL::PROCESS-OP CFFI-GROVEL:GROVEL-FILE)) #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "iolib/syscalls" "ffi-types">) [fast-method]
 5: ((SB-PCL::EMF ASDF/ACTION:PERFORM) #<unused argument> #<unused argument> #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "iolib/syscalls" "ffi-types">)
 6: ((LAMBDA NIL :IN ASDF/ACTION:CALL-WHILE-VISITING-ACTION))
 7: ((:METHOD ASDF/ACTION:PERFORM :AROUND (CFFI-GROVEL::PROCESS-OP CFFI-GROVEL::CC-FLAGS-MIXIN)) #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "iolib/syscalls" "ffi-types">) [fast-method]
 8: ((:METHOD ASDF/ACTION:PERFORM-WITH-RESTARTS :AROUND (T T)) #<CFFI-GROVEL::PROCESS-OP > #<CFFI-GROVEL:GROVEL-FILE "iolib/syscalls" "ffi-types">) [fast-method]
 9: ((:METHOD ASDF/PLAN:PERFORM-PLAN (T)) #<ASDF/PLAN:SEQUENTIAL-PLAN {1003F1B563}>) [fast-method]
10: ((FLET SB-C::WITH-IT :IN SB-C::%WITH-COMPILATION-UNIT))
11: ((:METHOD ASDF/PLAN:PERFORM-PLAN :AROUND (T)) #<ASDF/PLAN:SEQUENTIAL-PLAN {1003F1B563}>) [fast-method]
12: ((:METHOD ASDF/OPERATE:OPERATE (ASDF/OPERATION:OPERATION ASDF/COMPONENT:COMPONENT)) #<ASDF/LISP-ACTION:LOAD-OP > #<ASDF/SYSTEM:SYSTEM "iolib"> :PLAN-CLASS NIL :PLAN-OPTIONS NIL) [fast-method]
13: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> #<ASDF/LISP-ACTION:LOAD-OP > #<ASDF/SYSTEM:SYSTEM "iolib"> :VERBOSE NIL)
14: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
15: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) #<ASDF/LISP-ACTION:LOAD-OP > #<ASDF/SYSTEM:SYSTEM "iolib"> :VERBOSE NIL) [fast-method]
16: ((SB-PCL::EMF ASDF/OPERATE:OPERATE) #<unused argument> #<unused argument> ASDF/LISP-ACTION:LOAD-OP "iolib" :VERBOSE NIL)
17: ((LAMBDA NIL :IN ASDF/OPERATE:OPERATE))
18: ((:METHOD ASDF/OPERATE:OPERATE :AROUND (T T)) ASDF/LISP-ACTION:LOAD-OP "iolib" :VERBOSE NIL) [fast-method]
19: (ASDF/SESSION:CALL-WITH-ASDF-SESSION #<FUNCTION (LAMBDA NIL :IN ASDF/OPERATE:OPERATE) {10032ED4EB}> :OVERRIDE T :KEY NIL :OVERRIDE-CACHE T :OVERRIDE-FORCING NIL)
 --more--

The compile flags doesn't seem wrong (cc is the correct compiler to use for instance). After the failure the value of *cc-flags* is:

cffi-toolchain:*cc-flags*
 ; => ("-O2" "-pipe" "-Wall" "-Wundef" "-Wsign-compare" "-Wpointer-arith"
 ; "-fno-omit-frame-pointer" "-pthread" "-fno-pie")

Also, pkg-config seems fine:

% uname -a
OpenBSD venera 6.9 GENERIC.MP#47 amd64
% pkg-config --cflags --libs libfixposix
-I/usr/local/include -D__BSD_VISIBLE -pthread -L/usr/local/lib -lfixposix

I'm pretty new to common lisp, so please apologies. Do you have any additional pointers in things I should investigate?

Thanks,

guojing0 commented 2 years ago

Hi @omar-polo do you solve this issue? I have a somewhat similar problem like yours: https://github.com/atlas-engineer/nyxt/issues/1855#issuecomment-964222181

Thank you.

omar-polo commented 2 years ago

@guojing0 sorry, but I still have the same issue. It seems that grovel strips some -I flags, or maybe the lisp code doesn't call into pkg-config correctly, I don't know. I'm sorry I can't be more helpful :/

% pkg-config --cflags --libs libfixposix
-I/usr/local/include -D__BSD_VISIBLE -pthread -L/usr/local/lib -lfixposix
% uname -a
OpenBSD venera 7.0 GENERIC.MP#62 amd64
% rlwrap sbcl
This is SBCL 2.1.4.openbsd, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.
* (ql:quickload :iolib)
To load "iolib":
  Load 1 ASDF system:
    iolib
; Loading "iolib"
[package iolib/syscalls]...; cc -o /home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel-tmpZ7CBRM0G.o -c -O2 -pipe -Wall -Wundef -Wsign-compare -Wpointer-arith -fno-omit-frame-pointer -pthread -fno-pie -fPIC -I/home/op/quicklisp/dists/quicklisp/software/cffi_0.24.1/ /home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel.c
/home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel.c:6:10: fatal error: 'lfp.h' file not found
#include <lfp.h>
         ^~~~~~~
1 error generated.

debugger invoked on a CFFI-GROVEL:GROVEL-ERROR in thread #<THREAD "main thread" RUNNING {10018581C3}>: Subprocess #<UIOP/LAUNCH-PROGRAM::PROCESS-INFO {1002B46023}>
 with command ("cc" "-o" "/home/op/.cache/common-lisp/sbcl-2.1.4.openbsd-bsd-x64/home/op/quicklisp/local-projects/iolib/src/syscalls/ffi-types-unix__grovel-tmpZ7CBRM0G.o" "-c" "-O2" "-pipe" "-Wall" "-Wundef" "-Wsign-compare" "-Wpointer-arith" "-fno-omit-frame-pointer" "-pthread" ...)
 exited with error code 1

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
[....]

(On OpenBSD the package manager installs stuff into /usr/local/ and /usr/local/include is outside the default compiler search path, so even if I have lfp.h, it is in /usr/local/include/lfp.h and without -I/usr/local/include doesn't get seen)

guojing0 commented 2 years ago

@omar-polo thank you, still good to know.

nyx-land commented 2 years ago

Having the same issue with OpenBSD, and interestingly also when testing this on FreeBSD even though cffi has this block of code that's supposed to set the *cc-flags* variable to include the headers folder. So this should just work on FreeBSD, but in order to get iolib to load I have to also run (push "-I/usr/local/include" cffi-toolchain:*cc-flags*)

cffi has this line of code that is supposed to initialize the default parameters for *cc-flags*, but running that manually doesn't actually change the variable; if I run the function default-toolchain-parameters that ensure-toolchain-parameters wraps in some declarations for the lisp implementation and this unless check, then it seems to do what it's intended to do.

So this seems to be an upstream issue with cffi that might be able to be fixed rather easily.

guojing0 commented 2 years ago

I resolved my issue by installing Xcode, not just the command line tools.

nueidris commented 2 years ago

@omar-polo Could you please try #74? I don't have a OpenBSD environment right now, but it should fix the problem. Edit.: fixed upstream.

sionescu commented 2 years ago

I expect that 548537e should have fixed this issue too.

omar-polo commented 2 years ago

Yay, now it works out of the box, thanks!!