I use a third library OpenCTM to compress data in my CPlusPlus project.
After cmake and build, I got an executable file and copied it to the other place. Unfortunately, I always get the error code 127 from my web application. I didn’t figure it out because it’s successful to run the program in the shell environment.

The core logic in calling function is like the following code snippet.

function HandleFile( $filePath, $old_suffix, $new_suffix )
    $cmdStr = __DIR__ . '/3DFilesConverter' . ' ' . $filePath
    $output = "";
    $ret_code = 0;
    exec( $cmdStr, $output, $ret_code );
    if( 0 != $ret_code )
        echo "[error] ret_code: " . $ret_code . "\n";
        echo $cmdStr . "\n";
        print_r( $output );
        exit( -1 );
    return $output;

we can use the shell tool sed to read a few lines of a file. sed -n 2,10p upload_file.php

I’m sure PHP can find the executable file 3DFilesConverter. So the error code 127 means the shared library file can’t be found?

I wrote a small PHP script file and run it by user apache.

sudo -u apache php test.php

The same error showed and more details were there, can't load shared library ....

So I have to tell PHP where to find the library file.

Plan A

Mark where to find the library in the executable file.

Add these statements in the CMakeLists.txt

set( OPENCTM_LIB_DIR "../OpenCTM-1.0.3/lib" )


#SET(CMAKE_INSTALL_RPATH "\${ORIGIN}/lib") #the library path, ORIGIN means the path of exe

Run cmake and build the project again, get a new executable file.

Plan B

Change the variable LIBDIR in Makefile.linux in the folder OpenCTM.

#LIBDIR  = /usr/lib/
LIBDIR  = /usr/local/lib64/

Install the library again.

make -f Makefile.linux install

After that, you can run your web application successfully.

0 0 vote
Article Rating
Notify of
Inline Feedbacks
View all comments
A prohibited operation
Would love your thoughts, please comment.x