你如何从 cURLpp github repo 编译 example00?

How do you compile example00 from the cURLpp github repo?

我安装了 cURLpp,我正在尝试从他们的 GitHub 仓库编译 example00.cpp。但是,当我 运行 g++ example00.cpp -o example00 我得到这个输出:

/tmp/cc619KAL.o: In function main': example00.cpp:(.text+0x26): undefined reference tocurlpp::Cleanup::Cleanup()' example00.cpp:(.text+0x32): undefined reference to curlpp::Easy::Easy()' example00.cpp:(.text+0x93): undefined reference tocurlpp::Easy::perform()' example00.cpp:(.text+0x9f): undefined reference to curlpp::Easy::~Easy()' example00.cpp:(.text+0xae): undefined reference tocurlpp::Cleanup::~Cleanup()' example00.cpp:(.text+0xf5): undefined reference to curlpp::Easy::~Easy()' example00.cpp:(.text+0x10c): undefined reference tocurlpp::Cleanup::~Cleanup()' /tmp/cc619KAL.o:(.gcc_except_table+0x48): undefined reference to typeinfo for curlpp::LogicError' /tmp/cc619KAL.o:(.gcc_except_table+0x4c): undefined reference totypeinfo for curlpp::RuntimeError' /tmp/cc619KAL.o: In function curlpp::Option<std::string>::~Option()': example00.cpp:(.text._ZN6curlpp6OptionISsED2Ev[_ZN6curlpp6OptionISsED5Ev]+0x49): undefined reference tocurlpp::OptionBase::~OptionBase()' example00.cpp:(.text._ZN6curlpp6OptionISsED2Ev[_ZN6curlpp6OptionISsED5Ev]+0x6f): undefined reference to curlpp::OptionBase::~OptionBase()' /tmp/cc619KAL.o: In functioncurlpp::Option::Option(CURLoption, std::string const&)': example00.cpp:(.text._ZN6curlpp6OptionISsEC2E10CURLoptionRKSs[_ZN6curlpp6OptionISsEC5E10CURLoptionRKSs]+0x21): undefined reference to curlpp::OptionBase::OptionBase(CURLoption)' example00.cpp:(.text._ZN6curlpp6OptionISsEC2E10CURLoptionRKSs[_ZN6curlpp6OptionISsEC5E10CURLoptionRKSs]+0x5c): undefined reference tocurlpp::OptionBase::~OptionBase()' /tmp/cc619KAL.o:(.rodata._ZTVN6curlpp11OptionTraitISsL10CURLoption10002EEE[_ZTVN6curlpp11OptionTraitISsL10CURLoption10002EEE]+0x20): undefined reference to curlpp::OptionBase::operator<(curlpp::OptionBase const&) const' /tmp/cc619KAL.o:(.rodata._ZTVN6curlpp6OptionISsEE[_ZTVN6curlpp6OptionISsEE]+0x20): undefined reference tocurlpp::OptionBase::operator<(curlpp::OptionBase const&) const' /tmp/cc619KAL.o:(.rodata._ZTIN6curlpp6OptionISsEE[_ZTIN6curlpp6OptionISsEE]+0x10): undefined reference to typeinfo for curlpp::OptionBase' /tmp/cc619KAL.o: In functioncurlpp::UnsetOption::~UnsetOption()': example00.cpp:(.text._ZN6curlpp11UnsetOptionD2Ev[_ZN6curlpp11UnsetOptionD5Ev]+0x1f): undefined reference to curlpp::RuntimeError::~RuntimeError()' /tmp/cc619KAL.o: In functioncurlpp::Option::updateMeToOption(curlpp::OptionBase const&)': example00.cpp:(.text._ZN6curlpp6OptionISsE16updateMeToOptionERKNS_10OptionBaseE[_ZN6curlpp6OptionISsE16updateMeToOptionERKNS_10OptionBaseE]+0x30): undefined reference to typeinfo for curlpp::OptionBase' example00.cpp:(.text._ZN6curlpp6OptionISsE16updateMeToOptionERKNS_10OptionBaseE[_ZN6curlpp6OptionISsE16updateMeToOptionERKNS_10OptionBaseE]+0x5d): undefined reference tocurlpp::UnsetOption::UnsetOption(char const*)' /tmp/cc619KAL.o: In function curlpp::OptionTrait<std::string, (CURLoption)10002>::updateHandleToMe(curlpp::internal::CurlHandle*) const': example00.cpp:(.text._ZNK6curlpp11OptionTraitISsL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE[_ZNK6curlpp11OptionTraitISsL10CURLoption10002EE16updateHandleToMeEPNS_8internal10CurlHandleE]+0x59): undefined reference tocurlpp::UnsetOption::UnsetOption(std::string const&)' /tmp/cc619KAL.o: In function curlpp::Option<std::string>::getValue() const': example00.cpp:(.text._ZNK6curlpp6OptionISsE8getValueEv[_ZNK6curlpp6OptionISsE8getValueEv]+0x59): undefined reference tocurlpp::UnsetOption::UnsetOption(std::string const&)' /tmp/cc619KAL.o: In function void curlpp::internal::CurlHandle::option<void*>(CURLoption, void*)': example00.cpp:(.text._ZN6curlpp8internal10CurlHandle6optionIPvEEv10CURLoptionT_[_ZN6curlpp8internal10CurlHandle6optionIPvEEv10CURLoptionT_]+0x2d): undefined reference tocurl_easy_setopt' example00.cpp:(.text.ZN6curlpp8internal10CurlHandle6optionIPvEEv10CURLoptionT[ZN6curlpp8internal10CurlHandle6optionIPvEEv10CURLoptionT]+0x45): undefined reference to curlpp::libcurlRuntimeAssert(char const*, CURLcode)' /tmp/cc619KAL.o:(.rodata._ZTIN6curlpp11UnsetOptionE[_ZTIN6curlpp11UnsetOptionE]+0x10): undefined reference totypeinfo for curlpp::RuntimeError' collect2: error: ld returned 1 exit status

TheWatcher_,您需要在 curlpp 和 curl 中 link(将 -lcurlpp-lcurl 添加到您的 linker 行)。如需更完整的分步说明,请按以下步骤操作。

  1. 从 github 克隆最新的 curlpp。

    git clone https://github.com/jpbarrette/curlpp.git
    
  2. 进入git目录,准备编译

    cd curlpp
    ./autogen.sh
    ./configure
    
  3. 现在,让我们编译库以及所有示例

    make
    

总结:一旦构建了库,cd 到示例目录,运行 任何示例的以下内容(从 make 中提取)(替换需要示例编号的 00):

cd examples
g++ -DHAVE_CONFIG_H -I. -I../include/curlpp  -I../include   -g  -W -Wall -Werror    -I/usr/local/include -MT example00.o -MD -MP -MF .deps/example00.Tpo -c -o example00.o example00.cpp
mv -f .deps/example00.Tpo .deps/example00.Po
/bin/sh ../libtool --silent  --tag=CXX   --mode=link g++  -g  -W -Wall -Werror -I/usr/local/include -L../src/curlpp/ -lcurlpp -static -o example00 example00.o -lstdc++ -lcurl