未定义的符号:_NSLog 在 MacOS 上链接控制台 C++ 程序时

问题描述 投票:0回答:1

我正在尝试在 MacOS 上构建一个用 C++ 编写的控制台应用程序。该应用程序链接到第三方库,这需要一些 Apple 特定的东西:

ld: Undefined symbols:
  _NSLog, referenced from:
      onnxruntime::logging::AppleLogSink::SendImpl(std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000l>>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, onnxruntime::logging::Capture const&) in libonnxruntime_minimal.a[385](apple_log_sink.mm.o)
  ___CFConstantStringClassReference, referenced from:
       in libonnxruntime_minimal.a[385](apple_log_sink.mm.o)

可以在Linux上成功构建相同的应用程序。

我正在使用cmake。

请告知,如何正确添加我的

CMakeLists.txt
必要的Apple特定库来获取这些缺失的链接符号。

从我目前发现的情况来看,这应该位于某个名为“Foundation”的 Apple 库或框架中。但是,我找不到如何正确将其添加到

CMakeLists.txt
中。请指教。

macos cmake clang++ objective-c++ foundation
1个回答
0
投票

终于找到了这个:

  find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
  target_link_libraries(your_executable PRIVATE ${FOUNDATION_LIBRARY})

而且它有效,至少对我来说是这样。

© www.soinside.com 2019 - 2024. All rights reserved.