Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[curl:x64-osx] "symbols not found" linker errors with curl + cpr on macOS #7332

Closed
Toxe opened this issue Jul 19, 2019 · 3 comments
Closed

Comments

@Toxe
Copy link
Contributor

Toxe commented Jul 19, 2019

Hello,

when I am trying to compile a program with curl + cpr on macOS Mojave 10.14.5 (using clang 8.0.1-rc3 instead of Apple LLVM/Clang from Xcode) I get lots and lots of "Undefined symbols" linker errors (see below).

I am no expert here but it looks to me like curl is trying to use Apple Secure Transport for SSL but cannot resolve its symbols?

CMakeLists.txt

cmake_minimum_required(VERSION 3.14)
project("Test" LANGUAGES CXX)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(ENV{PKG_CONFIG_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")

find_package(cpr CONFIG REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(CURL REQUIRED)
find_package(ZLIB REQUIRED)

add_executable(message message.cpp)
target_compile_features(message PUBLIC cxx_std_17)
target_compile_options(message PRIVATE -Wall -Wextra -Wmost -pedantic -Wconversion -Wfloat-equal -Wold-style-cast -fcolor-diagnostics)
set_target_properties(message PROPERTIES CXX_EXTENSIONS OFF)
target_link_libraries(message PRIVATE cpr nlohmann_json nlohmann_json::nlohmann_json ${CURL_LIBRARIES} ${ZLIB_LIBRARY})

Configuration with cmake

$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=$SUITE_BUILD/vcpkg/scripts/buildsystems/vcpkg.cmake ..

-- The CXX compiler identification is Clang 8.0.1
-- Check for working CXX compiler: /Users/toxe/suite/build/bin/c++
-- Check for working CXX compiler: /Users/toxe/suite/build/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found nlohmann_json: /Users/toxe/suite/build/vcpkg/installed/x64-osx/share/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.6.1")
-- Found CURL: /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libcurl.a (found version "7.65.0-DEV")
-- Found ZLIB: /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libz.a (found version "1.2.11")
-- Configuring done
-- Generating done

Compiling & building with ninja

$ ninja -v

[1/2] /Users/toxe/suite/build/bin/c++   -isystem /Users/toxe/suite/build/vcpkg/installed/x64-osx/include -O3 -DNDEBUG   -Wall -Wextra -Wmost -pedantic -Wconversion -Wfloat-equal -Wold-style-cast -fcolor-diagnostics -std=c++17 -MD -MT CMakeFiles/message.dir/message.cpp.o -MF CMakeFiles/message.dir/message.cpp.o.d -o CMakeFiles/message.dir/message.cpp.o -c ../message.cpp
[2/2] : && /Users/toxe/suite/build/bin/c++  -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/message.dir/message.cpp.o  -o message  /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libcpr.a /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libcurl.a /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libz.a && :
FAILED: message 
: && /Users/toxe/suite/build/bin/c++  -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/message.dir/message.cpp.o  -o message  /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libcpr.a /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libcurl.a /Users/toxe/suite/build/vcpkg/installed/x64-osx/lib/libz.a && :
Undefined symbols for architecture x86_64:
  "_CFArrayAppendValue", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _append_cert_to_array in libcurl.a(sectransp.c.o)
  "_CFArrayCreate", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFArrayCreateMutable", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFArrayGetCount", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFArrayGetValueAtIndex", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFDataCreate", referenced from:
      _append_cert_to_array in libcurl.a(sectransp.c.o)
  "_CFDataGetBytePtr", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFDataGetLength", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFDictionaryCreate", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFDictionaryGetTypeID", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFDictionaryGetValue", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFGetTypeID", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFRelease", referenced from:
      _Curl_sectransp_shutdown in libcurl.a(sectransp.c.o)
      _Curl_sectransp_close in libcurl.a(sectransp.c.o)
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
      _CopyCertSubject in libcurl.a(sectransp.c.o)
      _append_cert_to_array in libcurl.a(sectransp.c.o)
  "_CFRetain", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFStringCompare", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_CFStringCreateWithCString", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFStringGetCString", referenced from:
      _CopyCertSubject in libcurl.a(sectransp.c.o)
  "_CFStringGetCStringPtr", referenced from:
      _CopyCertSubject in libcurl.a(sectransp.c.o)
  "_CFStringGetLength", referenced from:
      _CopyCertSubject in libcurl.a(sectransp.c.o)
  "_CFURLCreateDataAndPropertiesFromResource", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_CFURLCreateFromFileSystemRepresentation", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLClose", referenced from:
      _Curl_sectransp_shutdown in libcurl.a(sectransp.c.o)
      _Curl_sectransp_close in libcurl.a(sectransp.c.o)
  "_SSLCopyALPNProtocols", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SSLCopyPeerTrust", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SSLCreateContext", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLGetBufferedReadSize", referenced from:
      _Curl_sectransp_data_pending in libcurl.a(sectransp.c.o)
  "_SSLGetNegotiatedCipher", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SSLGetNegotiatedProtocolVersion", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SSLGetNumberSupportedCiphers", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLGetSessionState", referenced from:
      _Curl_sectransp_check_cxn in libcurl.a(sectransp.c.o)
  "_SSLGetSupportedCiphers", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLHandshake", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SSLRead", referenced from:
      _sectransp_recv in libcurl.a(sectransp.c.o)
  "_SSLSetALPNProtocols", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetCertificate", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetConnection", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetEnabledCiphers", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetIOFuncs", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetPeerDomainName", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetPeerID", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetProtocolVersionMax", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetProtocolVersionMin", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLSetSessionOption", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SSLWrite", referenced from:
      _sectransp_send in libcurl.a(sectransp.c.o)
  "_SecCertificateCopyCommonName", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecCertificateCopyLongDescription", referenced from:
      _CopyCertSubject in libcurl.a(sectransp.c.o)
  "_SecCertificateCreateWithData", referenced from:
      _append_cert_to_array in libcurl.a(sectransp.c.o)
  "_SecCertificateGetTypeID", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecIdentityCopyCertificate", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecIdentityCreateWithCertificate", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecItemCopyMatching", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecItemImport", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecKeyCopyExternalRepresentation", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SecPolicyCreateSSL", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecTrustCopyPublicKey", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SecTrustEvaluate", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SecTrustGetCertificateAtIndex", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecTrustGetCertificateCount", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_SecTrustSetAnchorCertificates", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_SecTrustSetAnchorCertificatesOnly", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "___CFConstantStringClassReference", referenced from:
      CFString in libcurl.a(sectransp.c.o)
  "_kCFAllocatorDefault", referenced from:
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
      _append_cert_to_array in libcurl.a(sectransp.c.o)
  "_kCFBooleanTrue", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kCFCopyStringDictionaryKeyCallBacks", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kCFTypeArrayCallBacks", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
      _sectransp_connect_step2 in libcurl.a(sectransp.c.o)
  "_kCFTypeDictionaryValueCallBacks", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecAttrLabel", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecClass", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecClassIdentity", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecImportItemIdentity", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecMatchLimit", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecMatchLimitAll", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecMatchPolicy", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
  "_kSecReturnRef", referenced from:
      _sectransp_connect_common in libcurl.a(sectransp.c.o)
ld: symbol(s) not found for architecture x86_64
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Installed packages

./vcpkg list | grep curl

cpr:x64-osx                                        1.3.0-7          C++ Requests is a simple wrapper around libcurl ...
curl:x64-osx                                       7.65.0-3         A library for transferring data with URLs
curl[sectransp]:x64-osx                                             SSL support (sectransp)
curl[ssl]:x64-osx                                                   Default SSL backend
@Toxe
Copy link
Contributor Author

Toxe commented Jul 19, 2019

As @past-due pointed out here (#7260 (comment)) it works when I change my CMakeLists.txt to:

find_package(CURL CONFIG REQUIRED)
target_link_libraries(message PRIVATE cpr nlohmann_json nlohmann_json::nlohmann_json CURL::libcurl ${ZLIB_LIBRARY})

This resolves the errors. So I would propose that the usage text after installing curl should be updated.

@Deadpikle
Copy link
Contributor

I'm not sure if this is applicable to this bug report or not, since I'm unaware of the internals of how cmake works in terms of this bugfix, but when attempting to link to libcurl.a in Xcode and receiving the same linker errors, you can resolve these linker issues by also linking to Security.framework from Xcode's "Linked Frameworks and Libraries" section. I'm not sure if the above CMakeLists.txt change would remove the need to do that manual link in Xcode.

(Also posting this same comment in the linked issue in case someone stumbles here from Google like me so they can have a temp fix before the PR comes through.)

@Toxe
Copy link
Contributor Author

Toxe commented Mar 5, 2020

I am closing this, as this has been fixed and no longer a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants