簡體   English   中英

鏈接器命令-沒有規則可成為第三方庫的目標

[英]Linker command - No rule to make target for 3rd party lib

在我的代碼中,我這樣引用pugixml:

#include "pugi/pugixml.hpp"

編譯時出現此錯誤:

  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

另一個問題是,我被告知將pugi作為附加的翻譯單元,並在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)

但是,當我嘗試在此更改后運行我的Makefile時,出現以下錯誤:

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

我真的不確定我要做什么。 pugi是應該擁有自己的Makefile來單獨構建它,還是應該讓我在Makefile中使其不是自己的“目標”?

編輯這是我的文件系統:

  • 根/生成文件
  • 根/ SRC / main.cpp中
  • 根/包括/ pugi / pugixml.hpp
  • 根/包括/ pugi / pugixml.cpp
  • 根/包括/ pugi / pugiconfig.hpp

在您的Makefile中,您嘗試編譯pugi/pugixml.cpp文件,但是在文件系統上,它位於include/pugi/pugixml.cpp (相對於Makefile本身)。 你應該:

  • 創建root/pugi目錄,並將pugixml.cpp文件放在pugixml.cpp

    要么

  • 或者在Makefile中用include/pugi/pugixml.cpp替換pugi/pugixml.cpp (但將源文件保存在include/子目錄中是個壞主意)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM