尝试使用pip安装bcrypt时出现此错误.我在几个地方安装了libffi(Xcode OS X SDK和自制软件),但我不知道如何告诉pip寻找它.有什么建议?
Downloading/unpacking bcrypt==1.0.2 (from -r requirements.txt (line 41))
Running setup.py egg_info for package bcrypt
OS/X: confusion between 'cc' versus 'gcc' (see issue 123)
will not use '__thread' in the C code
c/_cffi_backend.c:14:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
^
1 error generated.
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/Users/cody/virtualenvs/analytics/build/bcrypt/setup.py", line 104, in <module>
"Programming Language :: Python :: 3.3",
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = …Run Code Online (Sandbox Code Playgroud) 假设有一个以某种方式存储的参数列表,例如,在数组中.
给定一个函数指针,我如何调用它来传递存储的参数列表?
我不是试图将数组作为参数传递好.你明白了,好吗?我想将每个元素作为参数传递.一个数组只是为了说明,我可以将参数存储在一些元组结构中.另外,看看我手头有一个函数指针,并且可能有字符串格式的签名.我不是只想定义一个能够处理可变列表的函数.
我看到如何做到这一点的唯一方法是使用汇编(由__asm push等人)或这个:
void (*f)(...);
int main()
{
f = <some function pointer>;
int args[]; <stored in a array, just to illustrate>
int num_args = <some value>;
switch(num_args)
{
case 0:
f();
break;
case 1:
f(args[0]);
break;
case 2:
f(args[0], args[1]);
break;
/* etc */
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我不太喜欢这种做法......
还有另一种便携式和更短的形式吗?
有几种脚本语言可以调用C函数.
像Python或Ruby这样的脚本语言是如何做到的?他们如何以便携方式实现它?他们最近只是为几个平台或上面的平台使用组件吗?
看看我真的不是在询问参数封送的细节以及从脚本语言到C的其他内容,我只对内部如何构建脚本语言对C函数的调用感兴趣.
我将保留问题的标题,但我认为更好的方式是:
如何调用C函数,其指针和签名仅在运行时可用?
来自外国接口的PLT计划:
呼出是正常的函数调用.在动态设置中,我们创建一个"调用接口"对象,它指定(二进制)输入/输出类型; 此对象可以与任意函数指针和输入值数组一起使用,以执行函数的调用并检索其结果.这样做需要操纵堆栈并知道如何调用函数,这些是libffi处理的细节.
感谢@AnttiHaapala搜索,查找和指向libffi.这就是我所寻找的,它被一堆脚本语言所使用,它是一个可移植的库,在多个架构和编译器中实现.
我正在尝试按照参考https://rubygems.org/gems/travis安装gem install travis使用travis-cli,但出现以下错误。
尝试过这里提到的解决方案https://github.com/ffi/ffi/issues/653:
brew reinstall libffi
export LDFLAGS="-L/usr/local/opt/libffi/lib"
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
gem install travis
Run Code Online (Sandbox Code Playgroud)
framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr /include/ruby-2.3.0/ruby/ruby.h:24:10: 致命错误: 'ruby/config.h' 文件未找到 #include "ruby/config.h" ^~~~~~~~~ ~~~~~~ 产生了 1 个错误。检查的程序是:/* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char * framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr /include/ruby-2.3.0/ruby/ruby.h:24:10: 致命错误: 'ruby/config.h' 文件未找到 #include "ruby/config.h" ^~~~~~~~~ ~~~~~~ 产生了 1 个错误。检查的程序是:/* begin */ 1: #include "ruby.h" 2: 3: int main(int argc, char *argv) 4: { 5: 返回 0; 6: } /结束 …
使用VS11编译libffi会出现以下链接器错误
libffi\libffi-3.0.9\ms\Win32\Debug\ffi.dll : fatal error LNK1281: Unable to generate SAFESEH image.
Run Code Online (Sandbox Code Playgroud)
同一个项目正在使用VS10进行编译,但在使用VS2012进行自动升级后,它开始提供链接器错误
MSDN中的解释过于神秘且缺乏帮助
我可能会重建/SAFESEH:NO,但我不确定其含义.
请告知可能出现的问题.
我正在学习如何编程,我正在尝试安装 Cocoapods,但是我在sudo gem install cocoapods.
这就是我得到的:
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201006-615-fryp4a.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog …Run Code Online (Sandbox Code Playgroud) 在构建我的XCode项目时,对于我的一个cocoapod依赖项libffi,我得到了5个构建错误,所有这些都是 /Pods/libffi/ios/include/ffi_common.h:77:1: Unknown type name 'ffi_status'
我可以尝试调试它的任何想法?我已经尝试过清理这个项目了.
由于ruby和Haskell都支持FFI,
为了允许从脚本语言(用C编写)访问Win32 API,我想编写如下函数:
void Call(LPCSTR DllName, LPCSTR FunctionName,
LPSTR ReturnValue, USHORT ArgumentCount, LPSTR Arguments[])
Run Code Online (Sandbox Code Playgroud)
一般来说,它会调用任何Win32 API函数.
(LPSTR参数基本上用作字节数组 - 假设它们的大小正确,以便在函数外部采用正确的数据类型.另外我认为需要一些额外的复杂性来区分指针和非指针参数但我为了这个问题的目的,我忽略了这一点.
我遇到的问题是将参数传递给Win32 API函数.因为这些是stdcall我不能使用varargs所以'Call'的实现必须提前知道参数的数量,因此它不能是通用的...
我想我可以使用汇编代码(通过循环遍历参数,将每个推送到堆栈)来实现这一点但是在纯C中这是可能的吗?
更新:我已经标记了现在接受的'不可能'答案.如果基于C的解决方案曝光,我当然会改变这一点.
更新: ruby/dl看起来可能使用合适的机制实现.任何有关这方面的细节将不胜感激.
我最近一直在使用libffi,因为它使用了C API,所以任何抽象都是通过使用void指针(好的'C')来完成的.我正在创建一个使用此API的类(具有可变参数模板).类声明如下:(其中Ret=返回值和Args=函数参数)
template <typename Ret, typename... Args>
class Function
Run Code Online (Sandbox Code Playgroud)
在这个类中,我还声明了两个不同的函数(简化):
Ret Call(Args... args); // Calls the wrapped function
void CallbackBind(Ret * ret, void * args[]); // The libffi callback function (it's actually static...)
Run Code Online (Sandbox Code Playgroud)
我希望能够使用Call从CallbackBind; 那是我的问题.我不知道我应该如何将void*数组转换为模板化参数列表.这就是我想要的或多或少:
CallbackBind(Ret * ret, void * args[])
{
// I want to somehow expand the array of void pointers and convert each
// one of them to the corresponding template type/argument. The length
// …Run Code Online (Sandbox Code Playgroud) 我要做一个接口(比如一个包装器)允许从X86_64汇编代码调用它的调用约定到C函数,以及其他调用约定.最好的事情是非常"编译器独立"(juste修改包装器),所以我正在寻找将寄存器/堆栈内容放在编译器上的东西.我已经看过这里:P/Invoke和C#的自定义调用约定,它与我要做的事情很接近.目前,我正在使用GCC,但欢迎来自其他编译器的提示!
所以,这就是问题的最佳视图(自定义编码约定很奇怪):
pushq %r11 # saves r11 for call
movq 64bits_address %r11 # move a 64 bits address that points on a data structure
callq *8(%r11) # calls an address in the data structure
popq %r11 # restores %r11 ; return value is in the structure
Run Code Online (Sandbox Code Playgroud)
我需要能够调用"特殊"(包装)C函数; 这里的工作是在其他C函数之间调用调用.所以这个包装器需要找到%r11,保存所有寄存器并准备堆栈以便进一步调用.有没有一种正确的方法在C中执行此操作(使用一些内联asm)?
非常感谢