I am currently trying to use the curlcpp library; however, when I try to make an API call to OpenWeatherMaps I receive a "undefined symbols for architecture arm64" error below:
Undefined symbols for architecture arm64:
"__ZN4curl14curl_exceptionC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_", referenced from:
__ZN4curl19curl_easy_exceptionC1ERK8CURLcodeRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in main.cpp.o
"_curl_easy_setopt", referenced from:
__ZN4curl9curl_easy3addIL10CURLoption10002EEEvNS_6detail8option_tIXT_EE4typeE in main.cpp.o
"_curl_easy_strerror", referenced from:
__ZN4curl19curl_easy_exceptionC1ERK8CURLcodeRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE in main.cpp.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
I am currently using CLion, on M1 MacOS. My CMak files looks like this:
cmake_minimum_required(VERSION 3.24)
project(TerminalWeather)
set(CMAKE_CXX_STANDARD 23)
INCLUDE_DIRECTORIES(/opt/homebrew/Cellar/curlcpp/2.1/include/curlcpp)
LINK_LIBRARIES(/opt/homebrew/lib/libcurlcpp.dylib)
add_executable(TerminalWeather src/main.cpp)
This is what my main C++ file looks like:
#include <iostream>
#include <curlcpp/curl_easy.h>
using namespace std;
int main() {
using curl::curl_easy, curl::curl_easy_exception;
/* object handler to make the URL requests */
curl_easy handler;
handler.add<CURLOPT_URL>("https://api.openweathermap.org/data/2.5/weather?q={myCity}&units=metric&appid={myAPIKey}");
try {
handler.perform();
} catch(curl_easy_exception& ce) {
cout << ce.what() << endl;
}
return 0;
}
Could this error be because I am not linking the library properly? I am new to C++ and am not sure how to resolve the issue after looking everywhere.
Thank you all for the help