简体   繁体   English

在 Mac OS 上提升未定义符号

[英]Boost on Mac OS Undefined Symbols

I am encountering problems while compiling a c++ program including boost library.我在编译包含 boost 库的 C++ 程序时遇到问题。 The problems seem to have started occuring after I updated to Catalina, before everything worked correctly.在我更新到 Catalina 之后,在一切正常之前,问题似乎已经开始发生。

I use boost installed via homebrew ("brew install boost") and compile the program with g++ version 9 als installed with homebrew.我使用通过自制软件安装的boost(“brew install boost”)并使用自制软件安装的g ++版本9 als编译程序。

When compiling with "g++-9 -I/usr/local/include -L/usr/local/lib -lboost_serialization test.cc" the libararies are correctly found by the compiler but the following error occurs.使用“g++-9 -I/usr/local/include -L/usr/local/lib -lboost_serialization test.cc”编译时,编译器正确找到了库,但出现以下错误。 Below I include the error message and the test program that causes it.下面我包括错误消息和导致它的测试程序。

An interesting observation is that the name in the error message referenced as "cclgNgf3.o" changes each time I compile.一个有趣的观察结果是,每次编译时,错误消息中被引用为“cclgNgf3.o”的名称都会发生变化。 So far I also got "ccmG1kWi.o" and "cc25AYXh.o".到目前为止,我还得到了“ccmG1kWi.o”和“cc25AYXh.o”。

Undefined symbols for architecture x86_64:
  "boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      void boost::archive::save_access::save_primitive<boost::archive::text_oarchive, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(boost::archive::text_oarchive&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in cclgNgf3.o
  "boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::basic_ostream<char, std::char_traits<char> >&, unsigned int)", referenced from:
      boost::archive::text_oarchive::text_oarchive(std::basic_ostream<char, std::char_traits<char> >&, unsigned int) in cclgNgf3.o
  "boost::archive::basic_text_oprimitive<std::basic_ostream<char, std::char_traits<char> > >::~basic_text_oprimitive()", referenced from:
      boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl() in cclgNgf3.o
      boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl() in cclgNgf3.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
#include <boost/archive/text_oarchive.hpp>
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
    boost::archive::text_oarchive oa{cout};
    return 0;
}

On the off chance that it might be relevant when compiling with macOS clang compiler by invoking "g++ -lboost_serialization test.cc" a following error message is printed.如果通过调用“g++ -lboost_serialization test.cc”与 macOS clang 编译器编译时它可能相关,则会打印以下错误消息。

test.cc:8:32: error: no matching constructor for initialization of 'boost::archive::text_oarchive'
        boost::archive::text_oarchive oa{cout};
                                      ^
/usr/local/include/boost/archive/text_oarchive.hpp:98:28: note: candidate constructor (the implicit copy constructor) not viable: requires 1
      argument, but 0 were provided
class BOOST_SYMBOL_VISIBLE text_oarchive : 
                           ^
/usr/local/include/boost/archive/text_oarchive.hpp:102:5: note: candidate constructor not viable: requires at least argument 'os_', but no arguments
      were provided
    text_oarchive(std::ostream & os_, unsigned int flags = 0) :
    ^
test.cc:8:34: error: expected ';' at end of declaration
        boost::archive::text_oarchive oa{cout};
                                        ^
                                        ;
2 errors generated.

I built boost manually using gcc instead of clang and now it works.我使用 gcc 而不是 clang 手动构建了 boost,现在它可以工作了。 It would appear the brew version is built with clang and so then when I try to build my project using gcc we get the conflicts of standard libraries.看起来 brew 版本是用 clang 构建的,所以当我尝试使用 gcc 构建我的项目时,我们会遇到标准库的冲突。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 架构x86_64的未定义符号:OS X,Boost Log,CMake - Undefined symbols for architecture x86_64: OS X, Boost Log, CMake C++ Mac 上的 Boost oarchive 编译错误“架构 x86_64 的未定义符号:”。 使用 cmake - C++ Boost oarchive compile errror on Mac “Undefined symbols for architecture x86_64:”. Using cmake OS X,CMake,Boost:架构x86_64的未定义符号:“ boost :: system :: detail :: generic_category_instance” - OS X, CMake, Boost: Undefined symbols for architecture x86_64: “boost::system::detail::generic_category_instance” 在Mac OS X上提升makefile - boost makefile on Mac OS X ICU ustdio.h函数:使用CMake构建时,Mac OS上的未定义符号 - ICU ustdio.h functions: Undefined symbols on Mac OS when building with CMake C ++编译问题-体系结构x86_64的未定义符号-Mac Os X Mountain Lion - C++ Compilation Issue - Undefined symbols for architecture x86_64 - Mac Os X Mountain Lion g ++:Mac OS X上的链接器问题-体系结构x86_64的未定义符号 - g++: linker issue on Mac OS X - Undefined symbols for architecture x86_64 在Mac OS X上编译Aruco时出错:体系结构x86_64的未定义符号: - Error compiling Aruco on Mac OS X: Undefined symbols for architecture x86_64: 架构 x86_64 mac os 库 Clion 错误的未定义符号 - Undefined symbols for architecture x86_64 mac os library Clion error Mac OS - VS Code Insiders - Code Runner:架构 arm64 的未定义符号 - Mac OS - VS Code Insiders - Code Runner: Undefined symbols for architecture arm64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM