krups Posted March 26, 2007 Share Posted March 26, 2007 I have a C application foo.c which generates libFoo.so. foo.c #include <stdio.h> int FooBar(int value) { printf("Hello, World.\n"); return 1; } I want to load this libFoo.so into index.php file and call FooBar(); from libFoo.so. dl(libFoo.so); FooBar(); This does not work in PHP. What is the correct way to implement this functionality? -------------------------------------------------------------------------------------------- I tried to create an extension "myfile" (using ./ext_skel) which has FooBar() function defined. But I am not able to call FooBar() function defined in foo.c. Through PHP_FUNCTION(FooBar) (defined in ext/myfile.c), I want to call FooBar() implemented in foo.c. Kindly help how should this be implemented. Thanks, Krups Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 Are you sure you have the libFoo.so in the correct place. Are you getting any error messages? Are you using PHP4 or PHP5? Note: dl() is not supported in multithreaded Web servers. Use the extensions statement in your php.ini when operating under such an environment. However, the CGI and CLI build are not affected ! Note: As of PHP 5, the dl() function is deprecated in every SAPI except CLI. Use Extension Loading Directives method instead. Note: Since PHP 6 this function is disabled in all SAPIs, except CLI, CGI and embed. Note: dl() is case sensitive on Unix platforms. Note: This function is disabled in safe mode. http://us2.php.net/manual/en/function.dl.php Are you running in Safemode? Are you on a multithreaded enviroment. Are you sure the case is correct? Just making sure all the basic grounds are covered. Quote Link to comment Share on other sites More sharing options...
krups Posted March 28, 2007 Author Share Posted March 28, 2007 Hi, We are using apache server on linux with PHP 5. Could you please give me an example of steps so as to be able to build an extension and call a function from within third-party's C++ library. like: libFoo.so Thanks, Krupa Quote Link to comment Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 Take a look at the Zend API and examples. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.