php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62651 Extensions out of PHP source tree does not build anymore (link problem)
Submitted: 2012-07-24 09:50 UTC Modified: 2012-07-27 14:50 UTC
From: carlo dot pastorino at neologica dot it Assigned: cataphract (profile)
Status: Closed Package: Compile Failure
PHP Version: 5.4.5 OS: Windows 7
Private report: No CVE-ID: None
 [2012-07-24 09:50 UTC] carlo dot pastorino at neologica dot it
Description:
------------
I have a PHP extension which adds some "native" functions and zend classes to 
the PHP framework.
This extension is located out of the php source tree and it is built using a 
Visual Studio 2008 project which 
should set all the preprocessor definitions and .lib needed.
In order to build this extension i'm linking it to the php5ts.lib file included 
inside the php-devel-pack (which 
can be downloaded from here http://windows.php.net/downloads/releases/archives/) 
and, of course, including the 
*.h files provided with the php-devel-pack.

My Visual Studio solution worked fine using php5.2 and php5.3 includes and libs 
but it fails the compilation 
using the php5.4 php-devel-pack.

In particular I receive a link error:

unresolved external symbol "__declspec(dllimport) char const * (__cdecl* 
zend_new_interned_string)(char const 
*,int,int,void * * *)" (__imp_?zend_new_interned_string@@3P6APBDPBDHHPAPAPAX@ZA)

as if that symbol were not available from the php5ts.lib file.

I've generated a simpler Visual Studio solution containing ALL the files needed 
to build which should present 
the issue.

The solution can be downloaded here:

http://www.neologica.it/test_ext_vc9.7z

The source code contains a simple php extension and a zend class declaration 
(Test) having a method: "sayHello".
Compiling it using the configuration *_5.3 should produce the dll correctly 
while using the *_5.4 configuration 
should trigger the link error.

I'm not sure if this is some unfortunate case of undeclared macro in my code / 
solution, or if there is 
something that could be done in php source.

Test script:
---------------
1 - Extract the archive
2 - Open the solution with Visual Studio (2008 or 2010 is the same)
3 - Select "Release_5.4" or "Debug_5.4" from the build Solution configurations dropdown
4 - Build the extension.

Expected result:
----------------
php_test.dll correctly built

Actual result:
--------------
error LNK2001: unresolved external symbol "__declspec(dllimport) char const * 
(__cdecl* zend_new_interned_string)(char const *,int,int,void * * *)" (__imp_?
zend_new_interned_string@@3P6APBDPBDHHPAPAPAX@ZA)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-24 10:11 UTC] pajoye@php.net
This callback is part of the build (while interned string are only implemented in 
NTS).

Please check a build of your ext using the supported ways, phpize or to build with 
php to double check the actual problem.
 [2012-07-24 10:11 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-07-24 11:48 UTC] carlo dot pastorino at neologica dot it
Tested with phpize too and I obtained the same result. By the way the "phpize" way is simply 
not feasible for me/us and, if phpize makes it, Visual Studio should be able to make it too, 
right ?.

Please find my "phpize" project here : 
http://www.neologica.it/test_ext_phpize.7z

I must admint I never used phpize before on windows and I didn't think it was fully Windows 
compatible, however here is what I did (everything is provided with the 7z archive):

1] Created the "test" folder under "php_5.4/include/ext"
2] Moved my source files in this folder
3] Created the config.w32 file 
4] Opened the Visual Studio 2008 command prompt and moved to this folder
5] ..\..\..\phpize.bat
6] configure.bat --enable-test (here I had to add "bison.exe" location to my "PATH" and in 
the configure.js file I needed to add PHP_PGI and PHP_PGO definition)
7] nmake

and the result was the same as before.

Microsoft (R) Incremental Linker Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test_class.exe
/out:Release_TS\php_test.dll
/dll
/libpath:C:\php_5.4\lib\;C:\php_5.4
Release_TS\php_5.4\include\ext\test\test_class.obj
Release_TS\php_5.4\include\ext\test\test_ext.obj
C:\php_5.4\lib\php5ts.lib
kernel32.lib
ole32.lib
user32.lib
advapi32.lib
shell32.lib
ws2_32.lib
Dnsapi.lib
Release_TS\php_test.dll.res
   Creating library Release_TS\php_test.lib and object Release_TS\php_test.exp
test_class.obj : error LNK2019: unresolved external symbol "__declspec(dllimport
) char const * (__cdecl* zend_new_interned_string)(char const *,int,int,void * *
 *)" (__imp_?zend_new_interned_string@@3P6APBDPBDHHPAPAPAX@ZA) referenced in fun
ction "void __cdecl init_test_class(void * * *)" (?init_test_class@@YAXPAPAPAX@Z
)
Release_TS\php_test.dll : fatal error LNK1120: 1 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
\cl.exe"' : return code '0x2'
Stop.

Thank you in advance,
Carlo Pastorino
 [2012-07-24 11:48 UTC] carlo dot pastorino at neologica dot it
-Status: Feedback +Status: Open
 [2012-07-24 12:15 UTC] pajoye@php.net
-Status: Open +Status: Feedback
 [2012-07-24 12:15 UTC] pajoye@php.net
No idea about sln, it may differ as phpize generates some data.

About another test, can you try to build it with php?

php-sdk\vc9\x86
 |_ php-src
 |_ pecl
   |_ yourext

run buildconf from php-src, then:

configure <options needed>

etc.
 [2012-07-24 12:18 UTC] cataphract@php.net
Judging by the name of the symbol the linker can't find (namely it's name 
mangling), it's pretty obvious you're compiling your project as C++. Make sure 
you're including the PHP headers inside an extern "C" {} block.
 [2012-07-24 12:52 UTC] carlo dot pastorino at neologica dot it
-Status: Feedback +Status: Open
 [2012-07-24 12:52 UTC] carlo dot pastorino at neologica dot it
Thank you "cataphract" that solved the issue !! ;-)
I was actually including only "php.h" and changing that to:

extern "C" 
{
  #include "php.h"
}

did the trick.
I'm however quite confused, this same #include worked well for php5.3 without the "extern" thing. 
I took a look at, for example, "zend.h" header and I saw that all the declaration marked as ZEND_API are also 
wrapped by the "BEGIN_EXTERN_C()" and "END_EXTERN_C()" macros, but, inside the header "zend_string.h" which is 
the one causing me this link problem, all the ZEND_API declaration are not wrapped by those 2 macros.
Is there some particular reason for this ?

I also found that, now that you've enlightened me, another solution to my problem is to wrap those function in 
the zend_string.h like this:

BEGIN_EXTERN_C() // was missing previosly
ZEND_API extern const char *(*zend_new_interned_string)(const char *str, int len, int free_src TSRMLS_DC);
ZEND_API extern void (*zend_interned_strings_snapshot)(TSRMLS_D);
ZEND_API extern void (*zend_interned_strings_restore)(TSRMLS_D);
END_EXTERN_C() // was missing previosly

But in this case I really don't know if it works by chance or if it was really meant to be like it was before.
Thank you for you help!
Carlo Pastorino.
 [2012-07-27 14:47 UTC] cataphract@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ccffec74d070e862cae8d8752d716eabb53002b3
Log: Fix bug #62651: source level BC break
 [2012-07-27 14:48 UTC] cataphract@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=594397993dcbbf2fd90f6df23a2124c0239ec73e
Log: Fix bug #62651: source level BC break
 [2012-07-27 14:50 UTC] cataphract@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cataphract
 [2012-07-27 14:50 UTC] cataphract@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-07-27 16:53 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ccffec74d070e862cae8d8752d716eabb53002b3
Log: Fix bug #62651: source level BC break
 [2013-11-17 09:32 UTC] laruence@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src.git;a=commit;h=594397993dcbbf2fd90f6df23a2124c0239ec73e
Log: Fix bug #62651: source level BC break
 [2014-10-07 23:23 UTC] stas@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ccffec74d070e862cae8d8752d716eabb53002b3
Log: Fix bug #62651: source level BC break
 [2014-10-07 23:34 UTC] stas@php.net
Automatic comment on behalf of cataphract
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=ccffec74d070e862cae8d8752d716eabb53002b3
Log: Fix bug #62651: source level BC break
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 10 23:01:30 2024 UTC