c++ php and static library

爷,独闯天下 提交于 2019-12-12 17:17:24

问题


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.

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

Thx for advices! Appreciate!

EDIT: 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.


回答1:


This article might help. It shows how to create PHP extensions using C++.




回答2:


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

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

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

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:

  • use PHP's headers and interface your code directly with PHP
  • use a library wrapper which connects your calls to PHP
  • make your library into an executable and call it with PHP*

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



来源:https://stackoverflow.com/questions/7244482/c-php-and-static-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!