草庐IT

php - 奇怪的错误 : unresolved symbol when compiling with PHP7 on Windows

coder 2024-05-02 原文

我有一个奇怪的问题:我有一个项目,其中使用了PHP7 (php7ts.lib)。

PHP7 是我自己用 VS 2015 编译的:

--enable-mbstring=static --with-gd=static --with-iconv=static 
--enable-soap --enable-sockets --disable-ipv6 --with-dom 
--disable-bcmath --disable-cgi --disable-cli --enable-embed 
--with-bz2=static --enable-com-dotnet --enable-ctype 
--enable-mbregex=static --disable-mbregex-backtrack --enable-odbc --with-mp

相同的参数数量减少了:

--disable-all --without-libxml --without-dom --enable-sockets 
--enable-embed --enable-com-dotnet --enable-ctype --enable-odbc
--enable-debug 

BZip2 也是我自己编译的,它可以工作。 PHP7 的编译也可以,我得到了 .lib.dll 文件。然后我在编译项目时遇到了这个奇怪的错误:

error LNK2019: unresolved external symbol __imp__emalloc@@4 referenced in function
unresolved external symbol __imp__efree@@4
unresolved external symbol __imp__zval_dtor_func@@4
unresolved external symbol __imp__convert_to_string@@4
fatal error LNK1120: 4 unresolved externals

问题是:用自己编译的VS2013和PHP 5.6,一切正常。奇怪的是,未解析的符号指向的东西看起来并不特定于库。

我正在使用这里的部门:http://windows.php.net/downloads/php-sdk/deps-7.0-vc14-x86.7z

我知道,我错过了一些东西,但从这些消息中我看不出我错过了什么。

编辑:一些可能有用的新见解

好的,我现在可以获得更多信息,也许这有助于我们找到解决方案。

首先,我在 Debug模式下使用 32 位架构构建它。

cpp 文件中,有这些行(作为 __imp__efree@@4 错误的示例:

#if PHP_VERSION_ID >= 70000
    #   define FREE_ZVAL(z) efree_rel(z)
#endif

当我去定义 efree_rel(z) 时,我看到这一行(这与 Zend 有关):

#define efree_rel(ptr)                          _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC)

转到 _efree 的定义,我看到了这个:

ZEND_API void   ZEND_FASTCALL _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC);

这意味着该函数来自 PHP7/Zend。此行位于文件 zend_alloc.h 中。因此,据我所知,我应该查看此文件是否在 libdll 文件中导出。所以转储导出给了我(对于 lib):

Dump of file php7ts_debug.lib
File Type: LIBRARY
     Exports
       ordinal    name
                  _efree@@20

对于dll:

Dump of file php7ts_debug.dll
File Type: DLL
  Section contains the following exports for php7ts_debug.dll
    00000000 characteristics
    56EAF08F time date stamp Thu Mar 17 18:59:43 2016
        0.00 version
           1 ordinal base
        1531 number of functions
        1531 number of names
    ordinal hint RVA      name
        192   18 0028FFE0 _efree@@20 = @ILT+24528(_efree@@20)

我确定,我正在对正确的 lib 进行操作,因为重命名 lib 会给我一个错误,lib 丢失。

但是问题还没有解决

最佳答案

您需要将项目更新为 VS2015 项目。 所有未解析的函数都有 ZEND_FASTCALL 调用约定(zend_portability.h):

#if defined(__GNUC__) && ZEND_GCC_VERSION >= 3004 && defined(__i386__)
# define ZEND_FASTCALL __attribute__((fastcall))
#elif defined(_MSC_VER) && defined(_M_IX86) && _MSC_VER == 1700
# define ZEND_FASTCALL __fastcall
#elif defined(_MSC_VER) && _MSC_VER >= 1800 && !defined(__clang__)
# define ZEND_FASTCALL __vectorcall
#else
# define ZEND_FASTCALL
#endif

静态库 php7ts.lib 是使用 VS2015 和 __vectorcall 调用约定 ( https://msdn.microsoft.com/en-us/library/dn375768.aspx ) 构建的:

Function names are suffixed with two "at" signs (@@) followed by the number of bytes (in decimal) in the parameter list

关于php - 奇怪的错误 : unresolved symbol when compiling with PHP7 on Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36061216/

有关php - 奇怪的错误 : unresolved symbol when compiling with PHP7 on Windows的更多相关文章

随机推荐