php_embed_init() not found in php5.dll after compilation of Embed SAPI on Windows

[email protected] (Olivier Hoareau)
Newsgroups php.internals.win
Message-ID <[email protected]>
Hi !

I am currently trying to embed php5(ts).dll (embed shared) with a basic C++ program (basic command line program) on win32.

I successfully compiled PHP 5.4 (dev, today's snapshot) using the procedure described at https://wiki.php.net/internals/windows/stepbystepbuild on a brand new windows 7 32 bits installation (on a Virtual Machine), using Visual C++ 2008 Express and Windows SDK 6.1.

In a Windows SDK command shell (after a setenv /xp ... and buildconf ...), here is my configure (example for the non-Thread Safety version) :

$ configure --disable-all --enable-embed --disable-zts

("embed" sapi is enabled in the output log)

Then, I did :

$ nmake

I got the released dll in ./Release/php5.dll

Then, I tried to load this library dynamically using windows API in a dummy program that take the dll path as an argument :

--
#include <sapi/embed/php_embed.h>

int main(int argc, char *argv[])
{
	if (2 > argc) {
		printf("Syntax: %s <path/to/php5.dll>\n", argv[0]);
		return -1;
	}

	printf("Loading %s ...\n", argv[1]);

	HMODULE l = LoadLibrary(argv[1]);

	if (NULL == l) {
		printf("Error: unable to load '%s'\n", argv[1]);
		return -1;
	}

	printf("%s loaded.\n", argv[1]);

	typedef int (*php_embed_init_t) (int, char ** PTSRMLS_DC);

	php_embed_init_t php_embed_init = (php_embed_init_t) GetProcAddress(l, "php_embed_init");

	if (NULL == php_embed_init) {
		printf("Error: unable to find function php_embed_init() in PHP shared library (#%i)\n", GetLastError());
		return -1;
	}

	printf("php_embed_init() found.\n");

	php_embed_init(argc, argv PTSRMLS_CC);

	// ...
--

The program (phplibtest) successfully compiles (I added the right include paths and some defines).

I execute it using :

$ phplibtest C:\php-sdk\php54dev\vc9\x86\php5.4-201110111430\Release\php5.dll

And then got :

--
Loading C:\php-sdk\php54dev\vc9\x86\php5.4-201110111430\Release\php5.dll ...
C:\php-sdk\php54dev\vc9\x86\php5.4-201110111430\Release\php5.dll loaded.
Error: unable to find function php_embed_init() in PHP shared library (#127)
--

So, unable to find the php_embed_init() function in the php5.dll using GetProcAddress().
I checked the php5.dll using Dependency Walker, and unable to find php_embed_init() function in the list of exported function.

Can you help me figure out where is the problem ?

Thanks !

PS: I did the same failing test using PHP 5.3.8.

Olivier Hoareau
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.