0

我使用了 php-cpp

并创建程序并在共享库中正常工作,Makefile 在这里

但我想用静态库编译

所以我使用了这个命令:

/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

并创建图书馆ar rcs my_lib.a main.o base64.o md5.o

并用于编译

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

但返回错误:

/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

如何使用静态库进行编译?

4

2 回答 2

0

您还需要链接 phpcpp

于 2016-06-17T07:47:58.707 回答
0

您遇到的错误表明链接器找不到 php-cpp 库(您的编译代码引用了它的符号)。您必须使用-l标志指定库路径,然后像这样链接它:混合静态库和共享库

于 2016-06-17T07:48:19.460 回答