Search code examples
phpmacportslpsolve

how do you compile lp_solve toward macports php 5.4.2?


I followed the instructions here: http://lpsolve.sourceforge.net/5.5/PHP.htm#Compile_the_lpsolve_driver and downloaded the source from here: http://sourceforge.net/projects/lpsolve/ however when I type phpize from the directory of the source I get this message: Cannot find config.m4. Make sure that you run '/opt/local/bin/phpize' in the top level source directory of the module. I'm not sure what I'm doing wrong. I don't see a config.m4 anywhere (recursively) in the source directory for for lpsolve.


Solution

  • GOT IT.

    I've posted the steps below I took to get it working. It looks long but it's not that bad.

    These three sites were helpful in solving the issue.

    For building the correct library

    For malloc error when using make

    For function_entry error when using make

    Download: lp_solve_5.5.2.0_source.tar, lp_solve_5.5.2.0_PHP_source.tar

    From http://sourceforge.net/projects/lpsolve/files/lpsolve/5.5.2.0/

    These are the steps I took to get it working. First make sure your extensions directory is correct. I set mine back to the default (basically commenting it back out making it /opt/local/lib/php54/extensions/no-debug-non-zts-20100525) in the php.ini file. I also added the line extension=phplpsolve55.so. Use $ port unload apache2 and $ port load apache2 to restart the webserver.

    At this point in your terminal if you run $ php it should complain about not being able to find the phplpsolve55.so driver.

    Download and expand lp_solve_5.5_source.tar.gz into a directory named lp_solve_5.5.

    Download and expand lp_solve_5.5.2.0_PHP_source.tar into a directory named lp_solve_5.5_PHP.

    1) Build the lp_solve library in the source directory.

    $ cd lp_solve_5.5/lpsolve55
    $ sh ccc.osx
    

    This creates two new files in the lpsolve55 subdirectory:

    $ ls liblp*
    liblpsolve55.a     liblpsolve55.dylib
    

    For me the two files were located in lpsolve55\bin\osx64

    2) Install the lp_solve library.

    If not already in directory lpsolve55, cd to it. Copy liblpsolve55.a and liblpsolve55.dylib to /usr/local/lib (you may need to create /usr/local/lib first: $ sudo mkdir -p /usr/local/lib):

    $ sudo cp liblpsolve55.a liblpsolve55.dylib /usr/local/lib
    

    3) Test the build and installation.

    $ cd lp_solve_5.5/demo
    

    The ccc.osx script is broken. The good news is that version 5.5 of lp_solve fixes the "malloc.h" incompatibility on the Mac that was in earlier versions. The Unix/Linux script now works on OS X. Be patient... it may take several seconds to build 'demo':

    $ sh ccc
    

    The example problems in the demo should issue no errors and have "Excellent numeric accuracy ||*|| = 0":

    $ ./demo
    

    3) Build the php lpsolve library

    Now go into the PHP directory (lp_solve_5.5_PHP)

    $ cd lp_solve_5.5_PHP/extra/PHP
    $ phpize
    $ ./configure --enable-maintainer-zts --with-phplpsolve55=PATH TO SOURCE DIRECTORY
    

    *Where PATH TO SOURCE DIRECTORY is wherever you put the lp_solve_5.5*

    Then open PHPmod.c which should be in the current (lp_solve_5.5_PHP/extra/PHP) directory and change function_entry to zend_function_entry

    Then open hash.c which should also be in the same directory and change the line that says

    #include <malloc.h>
    

    to

    #if !defined(__APPLE__)
    #include <malloc.h>
    #endif
    

    ** note I only know to do this because I ran $ make on my machine before doing this and it complained about these two files*

    then do

    $ make
    $ cd modules
    $ sudo cp phplpsolve55.so /opt/local/lib/php54/extensions/no-debug-non-zts-20100525/
    

    Now running $ php shouldn't return any errors.

    Restart the apache server again and the extension should work. If not I'll help as much as I can.

    Hope this helps someone in the future.

    EDIT

    Just updated to Mavericks and everything works perfectly fine still. What I did was follow the steps outlined here, ran $ xcode-select --install after finishing the upgrade. Then I did $ sudo port selfupdate and finally ran the script at the bottom of the page to reload all my ports:

    curl -O https://svn.macports.org/repository/macports/contrib/restore_ports/restore_ports.tcl
    chmod +x restore_ports.tcl
    sudo ./restore_ports.tcl myports.txt
    

    Once that was done I did a $ sudo port load apache2 and everything still worked.