i have a test.c like below (in the same dir as the python file)
#include <stdio.h>
void myprint();
void myprint()
{
printf("hi\n");
}
and now i want to "import" it into my python script
from cffi import FFI
ffi = FFI()
ffi.cdef("void myprint();")
C = ffi.verify("""
#include "test.c"
""")
Using the examples from the cffi docs work fine.
Sorry for the large traceback error...
__pycache__/_cffi__xd52cd3eax2b8a27ce.c:185:18: fatal error: test.c: No such file or directory
#include "test.c"
^
compilation terminated.
Traceback (most recent call last):
File "/usr/lib/python3.4/distutils/unixccompiler.py", line 116, in _compile
extra_postargs)
File "/usr/lib/python3.4/distutils/ccompiler.py", line 909, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/usr/lib/python3.4/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/usr/lib/python3.4/distutils/spawn.py", line 162, in _spawn_posix
% (cmd, exit_status))
distutils.errors.DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/cffi/ffiplatform.py", line 48, in _build
dist.run_command('build_ext')
File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3.4/distutils/command/build_ext.py", line 348, in run
self.build_extensions()
File "/usr/lib/python3.4/distutils/command/build_ext.py", line 457, in build_extensions
self.build_extension(ext)
File "/usr/lib/python3.4/distutils/command/build_ext.py", line 512, in build_extension
depends=ext.depends)
File "/usr/lib/python3.4/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/usr/lib/python3.4/distutils/unixccompiler.py", line 118, in _compile
raise CompileError(msg)
distutils.errors.CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "pynfc_nfx.py", line 11, in <module>
""")
File "/usr/local/lib/python3.4/dist-packages/cffi/api.py", line 340, in verify
lib = self.verifier.load_library()
File "/usr/local/lib/python3.4/dist-packages/cffi/verifier.py", line 74, in load_library
self._compile_module()
File "/usr/local/lib/python3.4/dist-packages/cffi/verifier.py", line 139, in _compile_module
outputfilename = ffiplatform.compile(tmpdir, self.get_extension())
File "/usr/local/lib/python3.4/dist-packages/cffi/ffiplatform.py", line 25, in compile
outputfilename = _build(tmpdir, ext)
File "/usr/local/lib/python3.4/dist-packages/cffi/ffiplatform.py", line 51, in _build
raise VerificationError('%s: %s' % (e.__class__.__name__, e))
cffi.ffiplatform.VerificationError: CompileError: command 'x86_64-linux-gnu-gcc' failed with exit status 1
fatal error: test.c: No such file or directory
Try ffi.verify(..., include_dirs=['.'])
. The compiler is not called from the current directory, but instead from some temporary directory where cffi creates its temporary files.