Sorry for being a C newby. Could you please help me? I try to follow Sarah's
extending PHP book and fail to use the embeded PHP sapi:
I compile PHP5.3:
./configure --enable-embed
have a c "program":
#include <sapi/embed/php_embed.h>
int main(int argc, char *argv[])
{
PHP_EMBED_START_BLOCK(argc,argv)
PHP_EMBED_END_BLOCK()
return 0;
}
and a makefile:
CC=gcc
CFLAGS=-c -I/usr/local/include/php/
-I/usr/local/include/php/main
-I/usr/local/include/php/Zend
-I/usr/local/include/php/TSRM
-Wall -g
LDFLAGS=-L/usr/local/lib -lphp5
all: worker.c
$(CC) -o worker.o worker.c $(CFLAGS)
$(CC) -o worker worker.o $(LDFLAGS)
and get after running make:
gcc -c -I/usr/local/include/php/ -I/usr/local/include/php/main -
I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -Wall -g -o
worker.o worker.c
gcc -L/usr/local/lib -lphp5 -o worker worker.o
worker.o: In function main': /var/checkouts/gearman-php-worker/worker.c:5: undefined reference to
php_embed_init'
/var/checkouts/gearman-php-worker/worker.c:6: undefined reference to
`php_embed_shutdown'
collect2: ld returned 1 exit status
make: *** [all] Error 1
Thomas Koch, http://www.koch.ro
Excerpts from Thomas Koch's message of Mon Jul 13 16:15:10 -0400 2009:
worker.o: In function
main': /var/checkouts/gearman-php-worker/worker.c:5: undefined reference to
php_embed_init'
/var/checkouts/gearman-php-worker/worker.c:6: undefined reference to
`php_embed_shutdown'
collect2: ld returned 1 exit status
My guess is that you're missing some includes that you may need. Double
check your code against that in the book.
Cheers,
Edward
Hi Thomas,
gcc -c -I/usr/local/include/php/ -I/usr/local/include/php/main -
I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -Wall -g -o
worker.o worker.c
gcc -L/usr/local/lib -lphp5 -o worker worker.o
worker.o: In functionmain': /var/checkouts/gearman-php-worker/worker.c:5: undefined reference to
php_embed_init'
/var/checkouts/gearman-php-worker/worker.c:6: undefined reference to
`php_embed_shutdown'
collect2: ld returned 1 exit status
make: *** [all] Error 1
This worked for me, with your commands and program. Since its a linker
error, it seems likely that you haven't installed libphp5.so properly.
You didn't indicate that you ran make install, did you? If so, you may
want to verify that there is a libphp5.so in /usr/local/lib, and that
it is a shared library.
Paul
--
Paul Biggar
paul.biggar@gmail.com
Hi Thomas,
gcc -c -I/usr/local/include/php/ -I/usr/local/include/php/main -
I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -Wall -g -o
worker.o worker.c
gcc -L/usr/local/lib -lphp5 -o worker worker.o
worker.o: In functionmain': /var/checkouts/gearman-php-worker/worker.c:5: undefined reference to
php_embed_init'
/var/checkouts/gearman-php-worker/worker.c:6: undefined reference to
`php_embed_shutdown'
collect2: ld returned 1 exit status
make: *** [all] Error 1This worked for me, with your commands and program. Since its a linker
error, it seems likely that you haven't installed libphp5.so properly.
You didn't indicate that you ran make install, did you? If so, you may
want to verify that there is a libphp5.so in /usr/local/lib, and that
it is a shared library.
I don't think Thomas is completely off here.. For most of the morning
I've been trying to compile 5.3.0:
make clean; ./configure --enable-embed=shared; make && sudo make install
But when I went to build
#include <sapi/embed/php_embed.h>
int main(int argc, char *argv[]) {
PHP_EMBED_START_BLOCK(argc, argv);
PHP_EMBED_END_BLOCK();
return 0;
}
using
gcc -o embed_test embed_test.c -I/usr/local/include/php/
-I/usr/local/include/php/main -I/usr/local/include/php/Zend
-I/usr/local/include/php/TSRM -L/usr/local/lib -lphp5
I kept getting
/tmp/cc9OgNuw.o: In function main': embed_test.c:(.text+0x21): undefined reference to
php_embed_init'
embed_test.c:(.text+0x65): undefined reference to `php_embed_shutdown'
However, when I run config and make for 5.2.10, the test file compiles
just fine. Something must have changed between the two versions... Not
sure what, though.. Probably will dig deeper into this..
Thanks,
- Farley
On Mon, Jul 13, 2009 at 7:17 PM, Paul Biggarpaul.biggar@gmail.com
wrote:Hi Thomas,
gcc -c -I/usr/local/include/php/ -I/usr/local/include/php/main -
I/usr/local/include/php/Zend -I/usr/local/include/php/TSRM -Wall -
g -o
worker.o worker.c
gcc -L/usr/local/lib -lphp5 -o worker worker.o
worker.o: In functionmain': /var/checkouts/gearman-php-worker/worker.c:5: undefined reference to
php_embed_init'
/var/checkouts/gearman-php-worker/worker.c:6: undefined reference to
`php_embed_shutdown'
collect2: ld returned 1 exit status
make: *** [all] Error 1This worked for me, with your commands and program. Since its a
linker
error, it seems likely that you haven't installed libphp5.so
properly.
You didn't indicate that you ran make install, did you? If so, you
may
want to verify that there is a libphp5.so in /usr/local/lib, and that
it is a shared library.I don't think Thomas is completely off here.. For most of the morning
I've been trying to compile 5.3.0:make clean; ./configure --enable-embed=shared; make && sudo make
installBut when I went to build
#include <sapi/embed/php_embed.h>
int main(int argc, char *argv[]) {
PHP_EMBED_START_BLOCK(argc, argv);
PHP_EMBED_END_BLOCK();return 0;
}using
gcc -o embed_test embed_test.c -I/usr/local/include/php/
-I/usr/local/include/php/main -I/usr/local/include/php/Zend
-I/usr/local/include/php/TSRM -L/usr/local/lib -lphp5I kept getting
/tmp/cc9OgNuw.o: In function
main': embed_test.c:(.text+0x21): undefined reference to
php_embed_init'
embed_test.c:(.text+0x65): undefined reference to `php_embed_shutdown'However, when I run config and make for 5.2.10, the test file compiles
just fine. Something must have changed between the two versions... Not
sure what, though.. Probably will dig deeper into this..
This fixed in SVN already, the visibility for the two functions
stopped them being exposed in the library.
Scott