0

I've compiled some code and I have tons of errors, and I want to create a table which will show few things: the path of the source file, line number, and the undefined reference to. The first and 2nd are not much problem to dig out using a simple awk and print $1,$2 etc, but the undefined reference is problematic since it appears in different places in the output.

Here a snippet of the error log which I'm trying to parse with a script I want to write.

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:408: error: undefined reference to 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp:448: error: undefined reference to 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp:489: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp:489: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error: undefined reference to 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:279: error: undefined reference to 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:722: error: undefined reference to 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:72: error: undefined reference to 'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp:762: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:762: error: undefined reference to 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:463: error: undefined reference to 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error: undefined reference to 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error: undefined reference to 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h:649: error: undefined reference to 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:309: error: undefined reference to 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:649: error: undefined reference to 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h:309: error: undefined reference to 'fishy_proto::Service::Service()'

As you can see, line 1 and 14 shows the undefined reference in different place compared to the other lines.

Is there a way to run an awk which would ignore the exact location but will still bring the value the undefined reference to?

  • Show us expected output. – DevilaN Feb 20 '18 at 11:34
  • oh, I just want awk to pick the undefined reference to, for example: 'fishy_proto::Service::Service()' – Hetz Ben Hamo Feb 20 '18 at 11:42
1

Your sample output indicates that the "undefined reference" will always be the final awk field of a line. In awk, NF will be the number of fields, and $NF will be that field whose number is "the number of fields", ie. the final field, which is what you are asking for.

awk '{print "undefined reference = " $NF}'
  • you're right. How to I grab the final field? – Hetz Ben Hamo Feb 20 '18 at 11:47
  • I thought the answer was clear - use $NF in your print statement, as shown. – user1404316 Feb 20 '18 at 11:52
  • the answer was edited. – Hetz Ben Hamo Feb 20 '18 at 11:58
  • If you accept the answer, please mark it accepted. – user1404316 Feb 20 '18 at 12:01
1

the path of the source file, line number, and the undefined reference to

sed solution:

sed -E 's/^([^:]+):([0-9]+): error: undefined reference to (.*)/\1 \2 \3/' file

The output:

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h 408 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp 448 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp 489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp 489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 51 'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp 279 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp 319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 722 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h 72 'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp 762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp 463 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp 500 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp 500 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h 649 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h 309 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h 649 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h 309 'fishy_proto::Service::Service()'
0

If you don't mind to use perl:

perl -pe 's/^(.*?):(\d+): error: undefined reference to (.*)/\1\t\2\t\3/g'

The output of your example would look like this:

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h    408 'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp   448 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp   489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp   489 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  51  'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp  279 'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp  319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  319 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  722 'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h    72  'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp  762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  762 'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp  463 'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp  500 'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp  500 'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h   649 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h   309 'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h   649 'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h   309 'fishy_proto::Service::Service()'
0

I have done by below method using sed

sed -ne "s/\(.*error:\)\(.*reference to \)\('.*'\)/\1\3/p" inputfile

Output

out/target/product/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:408: error:'fishy_proto::Service::CopyFrom(fishy_proto::Service const&)'
base/fishy/fishy/impl/service.cpp:448: error:'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service.cpp:489: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service.cpp:489: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:51: error:'fishy_proto::ServiceList::~ServiceList()'
base/fishy/fishy/impl/service_registry.cpp:279: error:'fishy_proto::Request::Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:319: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:722: error:'fishy_proto::Request::Request()'
out/target/product/phaedra/gen/SHARED_LIBRARIES/libfishy_proto_intermediates/proto/base/fishy/fishy/prefix/fishy_proto/service_registry.pb.h:72: error:'fishy_proto::Request_Type_descriptor()'
base/fishy/fishy/impl/service_registry.cpp:762: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:762: error:'fishy_proto::Request::~Request()'
base/fishy/fishy/impl/service_registry.cpp:463: error:'fishy_proto::Service::Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error:'fishy_proto::Service::~Service()'
base/fishy/fishy/impl/service_registry.cpp:500: error:'fishy_proto::Service::~Service()'
external/protobuf/src/google/protobuf/arena.h:649: error:'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:309: error:'fishy_proto::ServiceGroup::ServiceGroup()'
external/protobuf/src/google/protobuf/arena.h:649: error:'fishy_proto::Service::Service()'
external/protobuf/src/google/protobuf/arena.h:309: error:'fishy_proto::Service::Service()'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.