@idakseart

Как заставить работать std::vector в gcc?

Добрый день, не работает простейший код с std::vector в gcc.
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  vector<int> tmpvector;
  tmpvector.reserve(10);
  return 0;
}


Вывод ошибки:
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 409.12 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0 -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/artem/Documents/Всякая всячина/КурсачВовк -ferror-limit 19 -fmessage-length 204 -stack-protector 1 -fblocks -fencode-extended-block-signature -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/kf/mlnscqp10dg752_wrbz0s_mr0000gn/T/main-549e84.o -x c++ main.cpp
clang -cc1 version 10.0.0 (clang-1000.11.45.5) default target x86_64-apple-darwin18.5.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o a.out /var/folders/kf/mlnscqp10dg752_wrbz0s_mr0000gn/T/main-549e84.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "std::logic_error::logic_error(char const*)", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "std::length_error::~length_error()", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in main-549e84.o
  "typeinfo for std::length_error", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "vtable for std::length_error", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
  "operator delete(void*)", referenced from:
      std::__1::__vector_base<int, std::__1::allocator<int> >::~__vector_base() in main-549e84.o
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::~__split_buffer() in main-549e84.o
  "operator new(unsigned long)", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "___cxa_allocate_exception", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in main-549e84.o
  "___cxa_free_exception", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "___cxa_throw", referenced from:
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
  "___gxx_personality_v0", referenced from:
      _main in main-549e84.o
      std::__1::vector<int, std::__1::allocator<int> >::reserve(unsigned long) in main-549e84.o
      std::__1::__split_buffer<int, std::__1::allocator<int>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<int>&) in main-549e84.o
      Dwarf Exception Unwind Info (__eh_frame) in main-549e84.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
  • Вопрос задан
  • 455 просмотров
Пригласить эксперта
Ответы на вопрос 1
doublench21
@doublench21
Какой язык выбран в Xcode для проекта? В macOS нету gcc, есть лишь алиас, который на самом деле clang. Попробуйте скомпилировать в терминале командой clang или g++.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы