Reputation: 1065
I'm currently working on creating a Makefile
for my simple c++ application.
At the moment, I'd like to compile a unique file, main.cpp
with the following headers and linker
g++ main.cpp -L/usr/local/Cellar/boost/1.65.1/lib -I/usr/local/Cellar/boost/1.65.1/include -lboost_system
When I prompt this command in the terminal, everything works well. However, when put into a 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}
and try to run make -f Makefile main
, it doesn't compile.
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
Looks like the argument are not correctly passed.
N.B : When I try to run
make -f Makefile main.cpp
, the compiler tells me that main.cpp is already up-to-date
I assume I'm doing something wrong within the Makefile
, but don't know what.
Thanks for your help,
Upvotes: 0
Views: 34
Reputation: 44238
In Makefile on the left of :
you define target, not source:
main.cpp:
tells make how to create main.cpp if it does not exist or older than dependencies (which are on the right of : in your case is nothing). You need to give your program a name and put that as a target:
programname: main.cpp
g++ main.cpp ${LDLIBS} ${LD} -o programname
Upvotes: 1