1
votes

In my code I make reference this pugixml like this:

#include "pugi/pugixml.hpp"

When compiling I get this 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

From another question I was told to pugi as an additional translation unit and link them accordingly like this in my Makefile:

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

all: $(TARGET)

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

clean:
    $(RM) $(TARGET)

However when I try to run my Makefile after this change I get this error:

make: *** No rule to make target `pugi/pugixml.cpp', needed by `main'.  Stop.

I'm really not sure what I am meant to be doing. Should pugi have it's own Makefile to build it individually, or should I give it is't own "target" in my Makefile?

Edit This is my file system:

  • root/Makefile
  • root/src/main.cpp
  • root/include/pugi/pugixml.hpp
  • root/include/pugi/pugixml.cpp
  • root/include/pugi/pugiconfig.hpp
1
I cannot reproduce issue. Do you actually have pugi/pugixml.cpp on your filesystem?myaut
@myaut I do yes, in the same directory as the .hppJ.Zil
I think posting filesystem hierarchy starting from directory with Makefile will be helpfulmyaut
@myaut Edited! Hope this helps shed some light. I really appreciate the help.J.Zil

1 Answers

1
votes

In your Makefile you try to compile pugi/pugixml.cpp file, but on filesystem it located in include/pugi/pugixml.cpp (relatively to Makefile itself). You should:

  • Create root/pugi directory and put pugixml.cpp file there

    OR

  • Or replace pugi/pugixml.cpp with include/pugi/pugixml.cpp in your Makefile (but keeping source files in include/ subdirectory is bad idea).