c ++ php和静态库 [英] c++ php and static library

查看:24
本文介绍了c ++ php和静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 library.a,其中包含一个 .cpp 和 .h 文件,其中包含许多类、嵌套类和方法.我想将这个静态库包含在一个 php 示例中并尝试使用它.我想提一下,我是 php 的新手.我已经在 test.cpp 文件中测试了我的 libray.a 并且它可以工作.如何创建 test.php 并测试我的 library.a?如果可能,请给我发送一些示例.

I've created a library.a that contains a .cpp and .h files with a lot of classes, nested classes and methods. I would like to include this static library inside a php example and try to work with it. I would like to mention that I am new to php. I've tested my libray.a inside a test.cpp file and it works. How can I create a test.php and test my library.a?If it;s possible please send me some examples.

我想提一下,我在 ubuntu 工作.g++ 是我的编译器.

I would like to mention that i am working in ubuntu. g++ was my compiler.

感谢您的建议!欣赏!

我想提一下我不想暴露我的 .CPP 代码的事实.我只想使用我的 .H 和 .A 文件.

I WOULD LIKE TO MENTION THE FACT THAT I DON'T WANT TO EXPOSE MY .CPP CODE. I JUST WANT TO USE MY .H AND .A FILES.

推荐答案

.a 文件不是自执行库.它是静态目标代码.它不能自己运行.

An .a file is not a self-executable library. It is static object code. It cannot run by itself.

PHP 没有加载器.它无法加载 .a 文件,您自己的操作系统也无法加载.

PHP doesn't have loaders. It can't load a .a file, neither your very own operating system can.

.a 文件需要附有适当的头文件(.h 文件).

An .a file needs to be accompanied by the appropriate headers (.h files).

如果你想在 PHP 中使用原生代码,你必须使用 PHP 的接口.看,就像用 C/C++ 构建的任何东西一样,PHP 对字符串(或大多数数据类型)的外观有自己的定义.

If you want to use native code within PHP, you must use PHP's interfaces. See, just like anything built with C/C++, PHP has it's own definition of what a string (or most data types) look like.

简而言之,您有两个选择:

In short, you have two options:

  • 使用 PHP 的标头并将您的代码直接与 PHP 连接
  • 使用库包装器将您的调用连接到 PHP
  • 使您的库成为可执行文件并使用 PHP* 调用它

*PHP 有很多 IPC 方法,所以这实际上是非常可行的.

*PHP has plenty IPC methods, so this is actually quite feasible.

这篇关于c ++ php和静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆