When you execute your line directly, $@ $^
is probably empty (check it yourself using echo
). In that case, the argument -lhello_ext
is not interpreted as a linker command for a library to add, but as the output name for your object file. That's why it works on the command line.
As for why it doesn't work in the Makefile: my guess would be that your library hello_ext
is located in the current directory. For the linker to find it, you need to put your library path information -L.
before you add the library.