体系结构的未定义符号 x86_64 (curlpp)
Undefined symbols for architecture x86_64 (curlpp)
在我正在处理的项目中,我尝试使用 curlpp 库来发出简单的 html GET 请求。我使用以下选项将 cpp 文件传递给 clang++:
clang++ -std=c++11 -stdlib=libc++ -I /usr/local/Cellar url_test.cpp
然后我得到这些错误:
Undefined symbols for architecture x86_64:
"curlpp::OptionBase::OptionBase(CURLoption)", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Option(CURLoption, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in url_test-541b93.o
"curlpp::OptionBase::~OptionBase()", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Option(CURLoption, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in url_test-541b93.o
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::~Option() in url_test-541b93.o
"curlpp::UnsetOption::UnsetOption(char const*)", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::updateMeToOption(curlpp::OptionBase const&) in url_test-541b93.o
curlpp::OptionTrait<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (CURLoption)10002>::updateHandleToMe(curlpp::internal::CurlHandle*) const in url_test-541b93.o
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getValue() const in url_test-541b93.o
"curlpp::RuntimeError::~RuntimeError()", referenced from:
curlpp::UnsetOption::~UnsetOption() in url_test-541b93.o
"curlpp::libcurlRuntimeAssert(char const*, CURLcode)", referenced from:
void curlpp::internal::CurlHandle::option<void*>(CURLoption, void*) in url_test-541b93.o
"curlpp::Easy::perform()", referenced from:
_main in url_test-541b93.o
"curlpp::Easy::Easy()", referenced from:
_main in url_test-541b93.o
"curlpp::Easy::~Easy()", referenced from:
_main in url_test-541b93.o
"curlpp::Cleanup::Cleanup()", referenced from:
_main in url_test-541b93.o
"curlpp::Cleanup::~Cleanup()", referenced from:
_main in url_test-541b93.o
"curlpp::OptionBase::operator<(curlpp::OptionBase const&) const", referenced from:
vtable for curlpp::OptionTrait<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (CURLoption)10002> in url_test-541b93.o
vtable for curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in url_test-541b93.o
"typeinfo for curlpp::LogicError", referenced from:
GCC_except_table0 in url_test-541b93.o
"typeinfo for curlpp::OptionBase", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::updateMeToOption(curlpp::OptionBase const&) in url_test-541b93.o
typeinfo for curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in url_test-541b93.o
"typeinfo for curlpp::RuntimeError", referenced from:
GCC_except_table0 in url_test-541b93.o
typeinfo for curlpp::UnsetOption in url_test-541b93.o
"_curl_easy_setopt", referenced from:
void curlpp::internal::CurlHandle::option<void*>(CURLoption, void*) in url_test-541b93.o
ld: symbol(s) not found for architecture x86_64
我认为这意味着编译器无法找到任何 curlpp 库。
这是我正在尝试的代码 运行:
1 #include <string>
2 #include <sstream>
3 #include <iostream>
4 #include <curlpp/cURLpp.hpp>
5 #include <curlpp/Easy.hpp>
6 #include <curlpp/Options.hpp>
7 #include <fstream>
8
9 using namespace curlpp::options;
10
11 int main(int, char **)
12 {
13 try
14 {
15 curlpp::Cleanup testCleanup;
16 curlpp::Easy miRequest;
17 miRequest.setOpt<Url>("http://www.wikipedia.org");
18 miRequest.perform();
19 }
20 catch(curlpp::RuntimeError & e)
21 {
22 std::cout << e.what() << std::endl;
23 }
24 catch(curlpp::LogicError & e)
25 {
26 std::cout << e.what() << std::endl;
27 }
28
29 return 0;
30 }
我正在 运行安装 macOS Sierra 10.12.4 Xcode 命令行工具和自制软件。我自制了 curlpp 库。我知道其他人能够使用 gcc 在 Ubuntu 16.04 上编译这个项目,所以我认为问题与 macOS 有关。
我是 cpp 的新手,所以非常感谢任何帮助!
你的问题是你没有链接你使用的库。添加库,应该就可以了。
你必须告诉编译器你的可执行文件要 link 哪些库。在您的情况下,通过添加选项 -lcurlpp -lcurl
.
解决了问题
顺便说一下,您提供的路径不正确,因为 headers 实际上位于 /usr/local/Cellar/curlpp/[此处插入版本]/include。无论如何,这个编译很好,没有为通过自制软件安装的库添加包含搜索路径,因为它会自动在 /usr/local/include 中创建 symlinks,这是默认位置之一要搜索的编译器。
在我正在处理的项目中,我尝试使用 curlpp 库来发出简单的 html GET 请求。我使用以下选项将 cpp 文件传递给 clang++:
clang++ -std=c++11 -stdlib=libc++ -I /usr/local/Cellar url_test.cpp
然后我得到这些错误:
Undefined symbols for architecture x86_64:
"curlpp::OptionBase::OptionBase(CURLoption)", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Option(CURLoption, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in url_test-541b93.o
"curlpp::OptionBase::~OptionBase()", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::Option(CURLoption, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in url_test-541b93.o
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::~Option() in url_test-541b93.o
"curlpp::UnsetOption::UnsetOption(char const*)", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::updateMeToOption(curlpp::OptionBase const&) in url_test-541b93.o
curlpp::OptionTrait<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (CURLoption)10002>::updateHandleToMe(curlpp::internal::CurlHandle*) const in url_test-541b93.o
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::getValue() const in url_test-541b93.o
"curlpp::RuntimeError::~RuntimeError()", referenced from:
curlpp::UnsetOption::~UnsetOption() in url_test-541b93.o
"curlpp::libcurlRuntimeAssert(char const*, CURLcode)", referenced from:
void curlpp::internal::CurlHandle::option<void*>(CURLoption, void*) in url_test-541b93.o
"curlpp::Easy::perform()", referenced from:
_main in url_test-541b93.o
"curlpp::Easy::Easy()", referenced from:
_main in url_test-541b93.o
"curlpp::Easy::~Easy()", referenced from:
_main in url_test-541b93.o
"curlpp::Cleanup::Cleanup()", referenced from:
_main in url_test-541b93.o
"curlpp::Cleanup::~Cleanup()", referenced from:
_main in url_test-541b93.o
"curlpp::OptionBase::operator<(curlpp::OptionBase const&) const", referenced from:
vtable for curlpp::OptionTrait<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, (CURLoption)10002> in url_test-541b93.o
vtable for curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in url_test-541b93.o
"typeinfo for curlpp::LogicError", referenced from:
GCC_except_table0 in url_test-541b93.o
"typeinfo for curlpp::OptionBase", referenced from:
curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >::updateMeToOption(curlpp::OptionBase const&) in url_test-541b93.o
typeinfo for curlpp::Option<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > in url_test-541b93.o
"typeinfo for curlpp::RuntimeError", referenced from:
GCC_except_table0 in url_test-541b93.o
typeinfo for curlpp::UnsetOption in url_test-541b93.o
"_curl_easy_setopt", referenced from:
void curlpp::internal::CurlHandle::option<void*>(CURLoption, void*) in url_test-541b93.o
ld: symbol(s) not found for architecture x86_64
我认为这意味着编译器无法找到任何 curlpp 库。
这是我正在尝试的代码 运行:
1 #include <string>
2 #include <sstream>
3 #include <iostream>
4 #include <curlpp/cURLpp.hpp>
5 #include <curlpp/Easy.hpp>
6 #include <curlpp/Options.hpp>
7 #include <fstream>
8
9 using namespace curlpp::options;
10
11 int main(int, char **)
12 {
13 try
14 {
15 curlpp::Cleanup testCleanup;
16 curlpp::Easy miRequest;
17 miRequest.setOpt<Url>("http://www.wikipedia.org");
18 miRequest.perform();
19 }
20 catch(curlpp::RuntimeError & e)
21 {
22 std::cout << e.what() << std::endl;
23 }
24 catch(curlpp::LogicError & e)
25 {
26 std::cout << e.what() << std::endl;
27 }
28
29 return 0;
30 }
我正在 运行安装 macOS Sierra 10.12.4 Xcode 命令行工具和自制软件。我自制了 curlpp 库。我知道其他人能够使用 gcc 在 Ubuntu 16.04 上编译这个项目,所以我认为问题与 macOS 有关。
我是 cpp 的新手,所以非常感谢任何帮助!
你的问题是你没有链接你使用的库。添加库,应该就可以了。
你必须告诉编译器你的可执行文件要 link 哪些库。在您的情况下,通过添加选项 -lcurlpp -lcurl
.
顺便说一下,您提供的路径不正确,因为 headers 实际上位于 /usr/local/Cellar/curlpp/[此处插入版本]/include。无论如何,这个编译很好,没有为通过自制软件安装的库添加包含搜索路径,因为它会自动在 /usr/local/include 中创建 symlinks,这是默认位置之一要搜索的编译器。