Giter Site home page Giter Site logo

ffi's Issues

FFI, ioctl/termios - request of help

Hello! Thank you for this project

I try to use it for call a ioctl(2) function.
The prototype of this function is int ioctl(int fd, unsigned long request, struct termios *term);
What I need is to declare a termios struct variable, and to call the ioctl function with a pointer on this variable.

So I have defined library and my prototype of functions like this:

#!/usr/bin/swipl

:- use_module(library(ffi)).
:- use_module(library(cerror)).

:- c_import("#include <sys/ioctl.h>
             #include <termios.h>",
            [ 'libc' ], [
                ioctl(int, ulong, -struct(termios), [int])
            ]).

I imagined declare a termios struct like this but c_alloc(Ptr, -struct(termios)) returned false.

:- initialization(main, main).

main(_Argv) :-
    c_alloc(Ptr, -struct(termios)), % ==> false
    ioctl(0, 21509, Ptr, _), nl.

Do can you help me with that?

source_file/2 causes test case to fail.

On Ubuntu 22.04 LTS on WSL 2 on Windows 10 with SWI-Prolog 8.5.15

groot@Galaxy:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
?- version.
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.15-86-g5a3743ab9)

?- pack_rebuild(ffi).

results in

% ERROR: /home/groot/.local/share/swi-prolog/pack/ffi/test/test_libc.pl:88:
%       test stat: failed

due to this line

once(source_file(_:stat(_,_), File)),

Changing to

once(source_file(File)),

results in success.

Compilation on mac

On a mac with os Mojave, swipl 8.1.3-26-g30498cd0a

doesn't compile, I get


% /Users/rzf/lib/swipl/bin/x86_64-darwin/swipl-ld -Wall -shared -O2 -gdwarf-2 -g3 -o lib/x86_64-darwin/ffi4pl.so c/ffi4pl.c -lffi
ERROR: In file included from c/ffi4pl.c:40:
ERROR: /Users/rzf/lib/swipl/include/SWI-Stream.h:58:10: fatal error: 'wchar.h' file not found
ERROR: #include <wchar.h>
ERROR:          ^~~~~~~~~
% 1 error generated.
% /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc returned code 256
% *** /Users/rzf/lib/swipl/bin/x86_64-darwin/swipl-ld exit status 1
% make: *** [lib/x86_64-darwin/ffi4pl.so] Error 1
ERROR: Process "process(path(make),[all])": exit status: 2
ERROR: In:
ERROR:   [14] throw(error(process_error(...,...),_14266))
ERROR:   [12] '$apply':forall(prolog_pack:member(all,...),prolog_pack:run_process(...,...,...)) at /Users/rzf/lib/swipl/boot/apply.pl:51
ERROR:    [7] <user>
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more 
´´´

Building needs to make $PACKSODIR?

Building needs to makedir $PACKSODIR

My troubleshooting steps

% Cloning into '/opt/logicmoo_workspace/packs_lib/ffi'...
Verify package status (anonymously)
        at "http://www.swi-prolog.org/pack/query" Y/n? n
Package:                ffi
Title:                  Dynamically call C functions
Installed version:      0.1
Author:                 Jan Wielemaker <[email protected]>
Maintainer:             Jan Wielemaker <[email protected]>
Packager:               Jan Wielemaker <[email protected]>
Home page:              https://github.com/JanWielemaker/ffi.git
Download URL:           https://github.com/JanWielemaker/ffi/archive/V*.zip
Run post installation scripts for pack "ffi" Y/n?
% checking for gcc...
% gcc
% checking whether the C compiler works...
% yes
% checking for C compiler default output file name... a.out
% checking for suffix of executables...
%
% checking whether we are cross compiling...
% no
% checking for suffix of object files...
% o
% checking whether we are using the GNU C compiler...
% yes
% checking whether gcc accepts -g...
% yes
% checking for gcc option to accept ISO C89...
% none needed
% checking how to run the C preprocessor...
% gcc -E
% checking for grep that handles long lines and -e...
% /bin/grep
% checking for egrep...
% /bin/grep -E
% checking for ANSI C header files...
% yes
% checking for sys/types.h...
% yes
% checking for sys/stat.h...
% yes
% checking for stdlib.h...
% yes
% checking for string.h...
% yes
% checking for memory.h...
% yes
% checking for strings.h...
% yes
% checking for inttypes.h...
% yes
% checking for stdint.h...
% yes
% checking for unistd.h...
% yes
% checking ffi.h usability...
% yes
% checking ffi.h presence...
% yes
% checking for ffi.h...
% yes
% checking ffi/ffi.h usability...
% no
% checking ffi/ffi.h presence...
% no
% checking for ffi/ffi.h...
% no
% checking dlfcn.h usability...
% yes
% checking dlfcn.h presence...
% yes
% checking for dlfcn.h...
% yes
% configure: creating ./config.status
% config.status: creating config.h
% mkdir -p lib/
% /root/lib/swipl-7.7.10/bin/x86_64-linux/swipl-ld -Wall -shared -O2 -gdwarf-2 -g3 -o lib/x86_64-linux/ffi4pl.so c/ffi4pl.c -lffi
% /usr/bin/ld: cannot open output file lib/x86_64-linux/ffi4pl.so:

So I went to the pack install dir

root@gitlab:/opt/logicmoo_workspace/packs_lib/ffi# make
mkdir -p lib/
/root/lib/swipl-7.7.10/bin/x86_64-linux/swipl-ld -Wall -shared -O2 -gdwarf-2 -g3 -o lib/x86_64-linux/ffi4pl.so c/ffi4pl.c -lffi
/usr/bin/ld: cannot open output file lib/x86_64-linux/ffi4pl.so: No such file or directory
collect2: error: ld returned 1 exit status
gcc returned code 256
*** /root/lib/swipl-7.7.10/bin/x86_64-linux/swipl-ld exit status 1
Makefile:23: recipe for target 'lib/x86_64-linux/ffi4pl.so' failed
make: *** [lib/x86_64-linux/ffi4pl.so] Error 1

Created directory and ran make

root@gitlab:/opt/logicmoo_workspace/packs_lib/ffi# mkdir 'lib/x86_64-linux/'

root@gitlab:/opt/logicmoo_workspace/packs_lib/ffi# make
mkdir -p lib/
/root/lib/swipl-7.7.10/bin/x86_64-linux/swipl-ld -Wall -shared -O2 -gdwarf-2 -g3 -o lib/x86_64-linux/ffi4pl.so c/ffi4pl.c -lffi
root@gitlab:/opt/logicmoo_workspace/packs_lib/ffi#

succeeded

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.