简体   繁体   中英

locating dependencies on windows php extension builds

I am writing a php extension for a library. I have a generic swig file to build wrappers for the library. This has been very successful so far on Python.

A user is trying to build the library for php and I am trying to help out. I generated the code using swig, and I can build the .dll extension using Visual Studio. The problem is getting it into php. When I build php_mylib.dll , it needs to find mylib.dll and it can't.

So I am trying to build via the command line a la: http://blog.benoitblanchon.fr/build-php-extension-on-windows/

I have put all the files to be compiled and the libraries needed (ie mylib64.lib and mylib64.dll) in a folder called mylib in the C:\\php-src\\ext folder with all the other extension folders.

The problem is I that I can't get the config.w32 file to communicate the location of mylib. Here is my config.w32 file (pretty standard -- you can see that I copied it from the curl config.w32 file):

// $Id$
// vim:ft=javascript

ARG_ENABLE("mylib", "mylib support", "no");

if (PHP_MYLIB != "no") {
    if (CHECK_LIB("mylib64.lib", "mylib", PHP_MYLIB) &&
            CHECK_HEADER_ADD_INCLUDE("mylib_cpp.h", "CFLAGS_MYLIB")
        ) {
        EXTENSION("mylib", "mylib_c_wrap.cpp", true);
        AC_DEFINE('HAVE_MYLIB', 1, 'Have mylib library');

        // TODO: check for curl_version_info
    } else {
        WARNING("mylib not enabled; libraries and headers not found");
    }
}

When I run buildconf and then configure --disable-all --enable-cli --enable-mylib it always shoots me the 'libraries and headers not found' warning from the script.

On Unix systems (config.m4) there appears to be a PHP_ADD_LIBRARY_WITH_PATH macro but I don't see any equivalent for windows. It seems like this is what I need.

I have also tried adding the full path to mylib into the system's path but to no avail. It seems like there might be an environment variable somewhere in the PHP build cosmos that needs to be set to find external dependencies, but I can't find any information about this.

It would also be good to do all this as a Visual Studio project -- easier for Windows users the world over. I have not seen anything on the web that looks like this.

By the way, I have successfully phpized this library using the same swig+phpize procedure on Linux (I followed this guide for the php part: http://www.sitepoint.com/install-php-extensions-source/ ) and it works beautifully.

In most cases you can use this info to build a PECL extension https://wiki.php.net/internals/windows/stepbystepbuild#building_pecl_extensions . Your config.w32 looks ok, though please note that that when depending on some additional library, usually it should be ARG_WITH(...) for semantics. Your lib stuff can be then put into the deps dir as in the wiki.

Another way could be passing --with-extra-libs and --with-extra-includes to configure. Those have to contain paths to *.lib and *.h dirs respectively. When using a static lib, that should be it, otherwise you'll need to place the corresponding *.dll onto the %path% for the ext to work.

Hope this helps, otherwise you can also gain some attention on the PHP mailing lists or specifically on #winphp-dev at freenode.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM