|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 13:00:01 2025 UTC |
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.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.