簡體   English   中英

帶有標題和鏈接器的Makefile

[英]Makefile with headers and linker

我目前正在為我的簡單c ++應用程序創建Makefile

目前,我想用以下標頭和鏈接器編譯一個唯一的文件main.cpp

g++ main.cpp -L/usr/local/Cellar/boost/1.65.1/lib -I/usr/local/Cellar/boost/1.65.1/include -lboost_system

當我在終端中提示此命令時,一切正常。 但是,當放入Makefile

SRC_FILES=main.cpp
LDLIBS=-L/usr/local/Cellar/boost/1.65.1/lib -I/usr/local/Cellar/boost/1.65.1/include
LD=-lboost_system

main.cpp:
    g++ main.cpp ${LDLIBS} ${LD}

並嘗試運行make -f Makefile main ,它不會編譯。

Undefined symbols for architecture x86_64:
  "boost::system::system_category()", referenced from:
      boost::asio::error::get_system_category() in main-100974.o
      ___cxx_global_var_init.2 in main-100974.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init in main-100974.o
      ___cxx_global_var_init.1 in main-100974.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

看來參數未正確傳遞。

NB:當我嘗試運行make -f Makefile main.cpp ,編譯器告訴我main.cpp is already up-to-date

我假設我在Makefile做錯了事,但不知道是什么。

謝謝你的幫助,

:左側的Makefile中,您定義目標,而不是源:

main.cpp:

告訴make如何創建main.cpp(如果它不存在或早於依賴項)(在:的右邊): 您需要給程序起一個名字並將其作為目標:

programname: main.cpp
      g++ main.cpp ${LDLIBS} ${LD} -o programname

暫無
暫無

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

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