Jump to content

Linking third party C library to php code / Extension


krups

Recommended Posts

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

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.