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

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.