0

I used php-cpp

and create program and worked fine in shared library and Makefile is Here

but i want compile with static library

So i used this command:

/opt/rh/devtool/opt/rh/devtoolset-3/root/usr/bin/g++ -c -std=c++11 md5.cpp -o md5.o /opt/rh/devtool/opt/rh/devtoolset-3/root/usr/bin/g++ -c -std=c++11 base64.cpp -o base64.o /opt/rh/devtool/opt/rh/devtoolset-3/root/usr/bin/g++ -c -std=c++11 main.cpp -o main.o

and create library with ar rcs my_lib.a main.o base64.o md5.o

and for compile used

/opt/rh/devtoolset-3/root/usr/bin/g++ -std=c++11 -o my_prog.o main.cpp base64.cpp md5.cpp my_lib.a

but return error:

/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/tmp/ccYj8JlX.o: In function `parsekit(Php::Parameters&)':
main.cpp:(.text+0x246): undefined reference to `Php::SERVER'
main.cpp:(.text+0x276): undefined reference to `Php::Value::~Value()'
main.cpp:(.text+0x82b): undefined reference to `Php::out'
main.cpp:(.text+0x851): undefined reference to `Php::Value::Value(bool)'
main.cpp:(.text+0x8f1): undefined reference to `Php::out'
main.cpp:(.text+0x917): undefined reference to `Php::Value::Value(bool)'
main.cpp:(.text+0xab2): undefined reference to `Php::Value::Value(std::string const&)'
main.cpp:(.text+0xb51): undefined reference to `Php::Value::~Value()'
/tmp/ccYj8JlX.o: In function `get_module':
main.cpp:(.text+0xe79): undefined reference to `Php::Extension::Extension(char const*, char const*, int)'
main.cpp:(.text+0xe92): undefined reference to `Php::Extension::~Extension()'
main.cpp:(.text+0xecc): undefined reference to `Php::Namespace::add(char const*, Php::Value (* const&)(Php::Parameters&), std::initializer_list<Php::Argument> const&)'
/tmp/ccYj8JlX.o: In function `Php::Value::operator std::string() const':
main.cpp:(.text._ZNK3Php5ValuecvSsEv[_ZNK3Php5ValuecvSsEv]+0x1f): undefined reference to `Php::Value::stringValue() const'
/tmp/ccYj8JlX.o: In function `Php::Super::operator[](char const*)':
main.cpp:(.text._ZN3Php5SuperixEPKc[_ZN3Php5SuperixEPKc]+0x24): undefined reference to `Php::Super::value()'
main.cpp:(.text._ZN3Php5SuperixEPKc[_ZN3Php5SuperixEPKc]+0x3d): undefined reference to `Php::Value::get(char const*, int) const'
main.cpp:(.text._ZN3Php5SuperixEPKc[_ZN3Php5SuperixEPKc]+0x49): undefined reference to `Php::Value::~Value()'
main.cpp:(.text._ZN3Php5SuperixEPKc[_ZN3Php5SuperixEPKc]+0x5a): undefined reference to `Php::Value::~Value()'
/tmp/ccYj8JlX.o: In function `Php::Extension::operator void*()':
main.cpp:(.text._ZN3Php9ExtensioncvPvEv[_ZN3Php9ExtensioncvPvEv]+0x14): undefined reference to `Php::Extension::module()'
collect2: error: ld returned 1 exit status

How can i compile with Static Library?

Community
  • 1
  • 1

2 Answers2

0

you need to link in phpcpp aswell

Stian Skjelstad
  • 2,277
  • 1
  • 9
  • 19
0

Errors you're getting indicate that linker can't find php-cpp library (your compiled code references its symbols). You have to specify the library path with -l flag and then link it like this: Mixing static libraries and shared libraries

Community
  • 1
  • 1
user37741
  • 370
  • 1
  • 10
  • i used `/opt/rh/devtoolset-3/root/usr/bin/g++ -std=c++11 -shared -fpic -lphpcpp -o my_prog.o main.cpp base64.cpp md5.cpp my_lib.a` and compiled, but is not static, and not work on other OS – john smith Jun 17 '16 at 07:57
  • `-fpic` is for shared library creation, you have to use `-static` (requires php-cpp also to be compiled as static) – user37741 Jun 17 '16 at 08:11
  • do you have static version of phpcpp installed? – user37741 Jun 17 '16 at 08:34
  • i used `/opt/rh/devtoolset-3/root/usr/bin/g++ -std=c++11 -static -lphpcpp -o my_prog.o main.cpp base64.cpp md5.cpp my_lib.a` but return error again on the my post – john smith Jun 17 '16 at 08:35
  • i installed with this document http://www.php-cpp.com/documentation/install i dont known is static or shared – john smith Jun 17 '16 at 08:37