首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在静态库中编译程序?

如何在静态库中编译程序?
EN

Stack Overflow用户
提问于 2016-06-17 15:31:07
回答 2查看 249关注 0票数 0

我使用了php-cpp

创建程序并在共享库和Makefile中正常工作,生成的文件是Here

但是我想使用静态库进行编译

所以我使用了这个命令:

/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

但返回错误:

代码语言:javascript
复制
/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

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

EN

回答 2

Stack Overflow用户

发布于 2016-06-17 15:47:59

您还需要在phpcpp中进行链接

票数 0
EN

Stack Overflow用户

发布于 2016-06-17 15:48:19

你得到的错误表明链接器找不到php-cpp库(你编译的代码引用了它的符号)。您必须使用-l标志指定库路径,然后像这样链接它:Mixing static libraries and shared libraries

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37875642

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档