简体   繁体   English

在 M1 Mac 上从 C++ 链接到 curl - arm64 的未定义符号

[英]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.

相关问题 架构 arm64 的未定义符号:m1 mac - Undefined symbols for architecture arm64: m1 mac “架构 arm64 的未定义符号”使用 g++-12 在 M1 mac 上构建基本 SFML 项目 - "Undefined symbols for architecture arm64" building basic SFML project on M1 mac with g++-12 OpenCV C++ 在 Macbook M1 芯片中给出架构 arm64 错误 - OpenCV C++ give architecture arm64 error in Macbook M1 chip 如何解决 M1 Mac 中的“未找到架构 arm64 的符号” - How to solve the "symbol(s) not found for architecture arm64" in M1 Mac 在 Mac arm64 架构 (M1) 上使用 ffmpeg 的 mpd 编译错误不清楚 - Unclear compile error for mpd with ffmpeg on Mac arm64 architecture (M1) MacOS 中架构 arm64 的未定义符号 - Undefined symbols for architecture arm64 in MacOS GLFW“架构 arm64 的未定义符号” - GLFW "Undefined symbols for architecture arm64" 在 iOS 应用程序中链接 static 库后架构 arm64 的未定义符号 - Undefined symbols for architecture arm64 after linking a static library in iOS app Python 在 Mac M1 上运行 C++ 扩展崩溃 ARM - Python Running C++ Extension Crashes On Mac M1 ARM 架构 arm64 的未定义符号:“_glClear”,引用自:main.cpp.o arm64 GLFW3 中的 _main - Undefined symbols for architecture arm64: "_glClear", referenced from: _main in main.cpp.o arm64 GLFW3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM