0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C++ あるソースをコンパイルした。リンクエラーが取れない。

Last updated at Posted at 2019-05-02

あるソースをコンパイルした。
include行を省略している。

適当に3つ4つincludeしてみた。
リンクエラーが取れない。

<この項は書きかけです。順次追記します。>

$ cc main.cpp
main.cpp:1:17: warning: using directive refers to implicitly-defined namespace
      'std'
using namespace std;
                ^
main.cpp:4:5: error: use of undeclared identifier 'vector'
    vector<int> a(6);
    ^
main.cpp:4:15: error: expected '(' for function-style cast or type construction
    vector<int> a(6);
           ~~~^
main.cpp:4:17: error: use of undeclared identifier 'a'
    vector<int> a(6);
                ^
main.cpp:5:5: error: use of undeclared identifier 'vector'
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
    ^
main.cpp:5:12: error: use of undeclared identifier 'vector'
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
           ^
main.cpp:5:22: error: expected '(' for function-style cast or type construction
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
                  ~~~^
main.cpp:5:24: error: use of undeclared identifier 'b'
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
                       ^
main.cpp:5:28: error: expected expression
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
                           ^
main.cpp:6:5: error: unknown type name 'lint'; did you mean 'int'?
    rep(i, 6)cin >> a[i];
    ^
main.cpp:2:23: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                      ^
main.cpp:6:5: error: use of undeclared identifier 'lint'; did you mean 'int'?
main.cpp:2:40: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                                       ^
main.cpp:6:14: error: use of undeclared identifier 'cin'
    rep(i, 6)cin >> a[i];
             ^
main.cpp:6:21: error: use of undeclared identifier 'a'
    rep(i, 6)cin >> a[i];
                    ^
main.cpp:7:5: error: unknown type name 'string'
    string junk; getline(cin, junk);
    ^
main.cpp:7:26: error: use of undeclared identifier 'cin'
    string junk; getline(cin, junk);
                         ^
main.cpp:8:5: error: unknown type name 'string'
    string text;
    ^
main.cpp:9:13: error: use of undeclared identifier 'cin'
    getline(cin,text);
            ^
main.cpp:11:5: error: unknown type name 'lint'; did you mean 'int'?
    rep(i,6){
    ^
main.cpp:2:23: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                      ^
main.cpp:11:5: error: use of undeclared identifier 'lint'; did you mean 'int'?
main.cpp:2:40: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                                       ^
main.cpp:12:21: warning: range-based for loop is a C++11 extension
      [-Wc++11-extensions]
        for (char c : text) {
                    ^
main.cpp:14:23: error: use of undeclared identifier 'b'
                buf = b[i][2];
                      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
2 warnings and 20 errors generated.
$ cc main.cpp
main.cpp:8:22: error: a space is required between consecutive right angle
      brackets (use '> >')
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
                     ^~
                     > >
main.cpp:8:24: error: non-aggregate type 'vector<vector<int> >' cannot be
      initialized with an initializer list
  ...b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0} ,{0,0,-1} };
     ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:9:5: error: unknown type name 'lint'
    rep(i, 6)cin >> a[i];
    ^
main.cpp:5:23: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                      ^
main.cpp:9:5: error: use of undeclared identifier 'lint'
main.cpp:5:40: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                                       ^
main.cpp:14:5: error: unknown type name 'lint'
    rep(i,6){
    ^
main.cpp:5:23: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                      ^
main.cpp:14:5: error: use of undeclared identifier 'lint'
main.cpp:5:40: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                                       ^
main.cpp:15:21: warning: range-based for loop is a C++11 extension
      [-Wc++11-extensions]
        for (char c : text) {
                    ^
main.cpp:38:5: error: unknown type name 'lint'
    rep(i, 6)if (b[i][2] == 1)cout << a[i]<<"\n";
    ^
main.cpp:5:23: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                      ^
main.cpp:38:5: error: use of undeclared identifier 'lint'
main.cpp:5:40: note: expanded from macro 'rep'
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
                                       ^
1 warning and 8 errors generated.

lintをintに修正。

$ cc main2.cpp
main2.cpp:8:22: error: a space is required between consecutive right angle
      brackets (use '> >')
    vector<vector<int>>b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0...
                     ^~
                     > >
main2.cpp:8:24: error: non-aggregate type 'vector<vector<int> >' cannot be
      initialized with an initializer list
  ...b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0} ,{0,0,-1} };
     ^   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main2.cpp:15:21: warning: range-based for loop is a C++11 extension
      [-Wc++11-extensions]
        for (char c : text) {
                    ^
1 warning and 2 errors generated.

エラー「non-aggregate type 'vector' cannot be initialized with an initializer list」の対処方法
https://marycore.jp/prog/xcode/non-aggregate-type-cannot-be-initialized-with-an-initializer/

$ cc main2.cpp -std=c++11
Undefined symbols for architecture x86_64:
  "std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
      _main in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::ios_base::getloc() const", referenced from:
      _main in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::logic_error::logic_error(char const*)", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "std::length_error::~length_error()", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)", referenced from:
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in main2-6b74d0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::push_back(char)", referenced from:
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      _main in main2-6b74d0.o
      std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in main2-6b74d0.o
  "std::__1::basic_istream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_istream<char, std::__1::char_traits<char> >&, bool)", referenced from:
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
  "std::__1::basic_istream<char, std::__1::char_traits<char> >::operator>>(int&)", referenced from:
      _main in main2-6b74d0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()", referenced from:
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(int)", referenced from:
      _main in main2-6b74d0.o
  "std::__1::cin", referenced from:
      _main in main2-6b74d0.o
  "std::__1::cout", referenced from:
      _main in main2-6b74d0.o
  "std::__1::ctype<char>::id", referenced from:
      _main in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::locale::~locale()", referenced from:
      _main in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::ios_base::__set_badbit_and_consider_rethrow()", referenced from:
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::__1::ios_base::clear(unsigned int)", referenced from:
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "std::terminate()", referenced from:
      ___clang_call_terminate in main2-6b74d0.o
  "typeinfo for std::length_error", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "vtable for std::length_error", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.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 main2-6b74d0.o
      std::__1::__vector_base<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::~__vector_base() in main2-6b74d0.o
  "operator new(unsigned long)", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "___cxa_allocate_exception", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "___cxa_begin_catch", referenced from:
      ___clang_call_terminate in main2-6b74d0.o
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "___cxa_end_catch", referenced from:
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
  "___cxa_free_exception", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "___cxa_throw", referenced from:
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
  "___gxx_personality_v0", referenced from:
      _main in main2-6b74d0.o
      std::__1::vector<int, std::__1::allocator<int> >::vector(unsigned long) in main2-6b74d0.o
      std::__1::vector<int, std::__1::allocator<int> >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >::allocate(unsigned long) in main2-6b74d0.o
      std::__1::vector<int, std::__1::allocator<int> >::vector(std::__1::vector<int, std::__1::allocator<int> > const&) in main2-6b74d0.o
      std::__1::basic_istream<char, std::__1::char_traits<char> >& std::__1::getline<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, char) in main2-6b74d0.o
      std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::__put_character_sequence<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned long) in main2-6b74d0.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

現在のソース。

main.cpp
#include <iostream>
#include <string>  
#include <vector>
#include <memory>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main() {
    vector<int> a(6);
    vector<vector<int> > b = { {0,0,1},{1,0,0} ,{0,1,0} ,{0,-1,0} ,{-1,0,0} ,{0,0,-1} };
    rep(i, 6)cin >> a[i];
    string junk; getline(cin, junk);
    string text;
    getline(cin,text);
    int buf;
    rep(i,6){
        for (char c : text) {
            if (c == 'E') {
                buf = b[i][2];
                b[i][2] = -b[i][1];
                b[i][1] = buf;
            }
            if (c == 'W') {
                buf = b[i][2];
                b[i][2] = b[i][1];
                b[i][1] = -buf;
            }
            if (c == 'S') {
                buf = b[i][2];
                b[i][2] = -b[i][0];
                b[i][0] = buf;
            }
            if (c == 'N') {
                buf = b[i][2];
                b[i][2] = b[i][0];
                b[i][0] = -buf;
            }
        }
    }
    rep(i, 6)if (b[i][2] == 1)cout << a[i]<<"\n";
}

<この記事は個人の過去の経験に基づく個人の感想です。現在所属する組織、業務とは関係がありません。>

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?