vendredi 17 avril 2015

Linker command failed - symbol not found on architecture

Finally after a lot of help I have been able to get my program to compile, or at least, it's closer, but now I have it spitting out this compile error:



main in main-bf0b72.o
"pugi::xml_node::children(char const*) const", referenced from:
_main in main-bf0b72.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1


I'm on an MacBook so I'm really not sure what I'm doing wrong but it seems perhaps that I am trying to compile it in the wrong way?


This is the full code



#include "pugi/pugixml.hpp"

#include <iostream>
#include <string>
#include <map>

int main() {
pugi::xml_document doca, docb;
std::map<std::string, pugi::xml_node> mapa, mapb;

if (!doca.load_file("a.xml") || !docb.load_file("b.xml"))
return 1;

for (auto& node: doca.child("site_entries").children("entry")) {
const char* id = node.child_value("id");
mapa[id] = node;
}

for (auto& node: docb.child("site_entries").children("entry")) { // <-- here
const char* idcs = node.child_value("id");
if (!mapa.erase(idcs)) { // <-- here
mapb[idcs] = node; // <-- here
}
}

for (auto& ea: mapa) {
std::cout << "Removed:" << std::endl;
ea.second.print(std::cout);
}

for (auto& eb: mapb) {
std::cout << "Added:" << std::endl;
eb.second.print(std::cout);
}

}


Full error trace if that helps



src/main.cpp:14:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto& node: doca.child("site_entries").children("entry")) {
^
src/main.cpp:14:20: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (auto& node: doca.child("site_entries").children("entry")) {
^
src/main.cpp:19:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto& node: docb.child("site_entries").children("entry")) { // <-- here
^
src/main.cpp:19:20: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (auto& node: docb.child("site_entries").children("entry")) { // <-- here
^
src/main.cpp:26:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto& ea: mapa) {
^
src/main.cpp:26:18: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (auto& ea: mapa) {
^
src/main.cpp:31:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
for (auto& eb: mapb) {
^
src/main.cpp:31:18: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
for (auto& eb: mapb) {
^
8 warnings generated.
Undefined symbols for architecture x86_64:
"pugi::xml_document::load_file(char const*, unsigned int, pugi::xml_encoding)", referenced from:
_main in main-bf0b72.o
"pugi::xml_document::xml_document()", referenced from:
_main in main-bf0b72.o
"pugi::xml_document::~xml_document()", referenced from:
_main in main-bf0b72.o
"pugi::xml_named_node_iterator::operator++()", referenced from:
_main in main-bf0b72.o
"pugi::xml_node::xml_node()", referenced from:
std::__1::map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, pugi::xml_node, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const, pugi::xml_node> > >::__construct_node_with_key(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main-bf0b72.o
"pugi::xml_parse_result::operator bool() const", referenced from:
_main in main-bf0b72.o
"pugi::xml_named_node_iterator::operator*() const", referenced from:
_main in main-bf0b72.o
"pugi::xml_named_node_iterator::operator!=(pugi::xml_named_node_iterator const&) const", referenced from:
_main in main-bf0b72.o
"pugi::xml_node::child_value(char const*) const", referenced from:
_main in main-bf0b72.o
"pugi::xml_node::child(char const*) const", referenced from:
_main in main-bf0b72.o
"pugi::xml_node::print(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*, unsigned int, pugi::xml_encoding, unsigned int) const", referenced from:
_main in main-bf0b72.o
"pugi::xml_node::children(char const*) const", referenced from:
_main in main-bf0b72.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1


Any help would be appreciated


EDIT: This is my Makefile



CC = g++
CFLAGS = -g -Wall
SRC = src
INCLUDES = include
TARGET = main

all: $(TARGET)

$(TARGET): $(SRC)/$(TARGET).cpp
$(CC) $(CFLAGS) -I $(INCLUDES) -o $@ $^

clean:
$(RM) $(TARGET)

Aucun commentaire:

Enregistrer un commentaire