c++ php and static library
I've created a library.a tha开发者_如何学编程t 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.
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.
精彩评论