[英]Linking to curl from C++ on M1 Mac - undefined symbols for arm64
I have an existing project that was on Windows and Linux.我有一个在 Windows 和 Linux 上的现有项目。 I recently got a mac for the first time and I am trying to set it up for C++ development but I'm having an issue linking to curl I believe.
我最近第一次获得了 Mac,我正在尝试将其设置为 C++ 开发,但我相信我在链接到 curl 时遇到问题。
From what I've seen, curl supports the M1 arm based chip via homebrew which I installed using homebrew install curl
.据我所知,curl 通过自制软件支持基于 M1 arm 的芯片,我使用
homebrew install curl
。
Below is my make file下面是我的制作文件
SOURCES = DataDogStatsD.cpp DDEvent.cpp Helpers.cpp
lib_name = libDataDogStatsD.so.1.1.0.5
curl_include = /usr/local/include/curl
rapidjson_inc_path = /usr/local/include/rapidjson
OBJECTS = $(SOURCES:.cpp=.o)
CFLAGS = -fpic -c $(SOURCES) -Wall -g -Iinclude -std=c++11 -I/usr/include -I$(curl_include) -I$(rapidjson_inc_path)
CC = g++
LDFLAGS = -lpthread -pthread -lm -L/opt/homebrew/opt/curl/lib
.PHONY: clean
default:
$(CC) -shared -Wl,-install_name,libDataDogStatsD.so.1 -o $(lib_name) $(OBJECTS) $(LDFLAGS)
ln -sf $(lib_name) libDataDogStatsD.so
clean:
rm -vf $(OBJECTS) depend $(lib_name)
depend: $(SOURCES)
$(CC) $(CFLAGS) > depend
-include depend
When I run make, I get the following:当我运行 make 时,我得到以下信息:
g++ -fpic -c DataDogStatsD.cpp DDEvent.cpp Helpers.cpp -Wall -g -Iinclude -std=c++11 -I/usr/include -I/usr/local/include/curl -I/usr/local/include/rapidjson > depend
g++ -shared -Wl,-install_name,libDataDogStatsD.so.1 -o libDataDogStatsD.so.1.1.0.5 DataDogStatsD.o DDEvent.o Helpers.o -lpthread -pthread -lm -L/opt/homebrew/opt/curl/lib
Undefined symbols for architecture arm64:
"_curl_easy_cleanup", referenced from:
DataDogStatsD::event(DDEvent, bool, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
DataDogStatsD::sendDDEventinthread(DDEvent, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
"_curl_easy_getinfo", referenced from:
DataDogStatsD::event(DDEvent, bool, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
DataDogStatsD::sendDDEventinthread(DDEvent, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
"_curl_easy_init", referenced from:
DataDogStatsD::initCurl(DDEvent, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, curl_slist*, char const*) in DataDogStatsD.o
"_curl_easy_perform", referenced from:
DataDogStatsD::event(DDEvent, bool, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
DataDogStatsD::sendDDEventinthread(DDEvent, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
"_curl_easy_setopt", referenced from:
DataDogStatsD::initCurl(DDEvent, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, curl_slist*, char const*) in DataDogStatsD.o
"_curl_easy_strerror", referenced from:
DataDogStatsD::event(DDEvent, bool, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
DataDogStatsD::sendDDEventinthread(DDEvent, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
"_curl_slist_append", referenced from:
DataDogStatsD::initCurl(DDEvent, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, curl_slist*, char const*) in DataDogStatsD.o
"_curl_slist_free_all", referenced from:
DataDogStatsD::event(DDEvent, bool, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
DataDogStatsD::sendDDEventinthread(DDEvent, void (*)(bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)) in DataDogStatsD.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [default] Error 1
I've tried setting the -arch to x86_64 as a test on on the LDFLAGS and it then successfully compiles and creates the library, but I don't really see that I should need to build x86_64 when it should be built for M1, and therefore be quicker as it won't have to go through Rosetta.我已经尝试将 -arch 设置为 x86_64 作为对 LDFLAGS 的测试,然后它成功编译并创建了库,但我真的不认为我应该在应该为 M1 构建 x86_64 时构建它,并且因此更快,因为它不必通过罗塞塔 go。
If I run lipo -info /opt/homebrew/opt/curl/bin/curl
to check the architecture of the library I get the following:如果我运行
lipo -info /opt/homebrew/opt/curl/bin/curl
来检查库的体系结构,我会得到以下信息:
Non-fat file: /opt/homebrew/opt/curl/bin/curl is architecture: arm64
So curl looks to be correct so not sure why I'm getting error undefined symbols for arm64所以 curl 看起来是正确的,所以不知道为什么我收到错误 undefined symbols for arm64
I don't see any reference to the curl
library in your makefile.我在您的 makefile 中没有看到对
curl
库的任何引用。 To rectify this, you (probably) need to add -lcurl
to your LDFLAGS
.要纠正这个问题,您(可能)需要将
-lcurl
添加到您的LDFLAGS
中。
Also, /opt/homebrew/opt/curl/bin/curl
is the curl executable, not the library.此外,
/opt/homebrew/opt/curl/bin/curl
是 curl 可执行文件,而不是库。 That is (probably) /opt/homebrew/opt/curl/lib/libcurl.so
那是(可能)
/opt/homebrew/opt/curl/lib/libcurl.so
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.