title: How to use ld to link obj files produced by gcc
body: <p>These days I'm reading APUE and setting up the Makefile myself instead of using the existing .mk Makefile provided by the book's website. My Makefile goes like this: </p>
  
  <pre><code>CC=gcc
  LD=ld
  CC_FLAGS= -c -I ./include/ -Wall -Wextra
  LD_FLAGS= -e main -lc
  LIB_OBJS= ./lib/*.o #There'are about 30 .c files in lib, \
  most of which are wrap of error handling routines or simplified APIs. \
  So I don't copy them all in the code block
  
  all: 
  
  ls: ls.c $(LIB_OBJS)
          $(CC) $(CC_FLAGS) -o ls.o ls.c
          $(LD) $(LD_FLAGS) -o ls ls.o ./lib/error.o
  
  $(LIB_OBJS):
          cd ./lib; \
          make
  
  clean:
          cd ./lib; \
          make clean
          rm ./ls
  </code></pre>
  
  <p>The Makefile in ./lib is pretty much similar to this one as it just gcc -c all .c files in that directory and doesn't do any linking works. And the ls.c is the first piece of code in Chapter One which just list every element of the given dirent. 
  My problem is, my Makefile CAN PRODUCE a executable without any error printed but this file is not executable at all. Whenever I ./ls with the x privilege, bash returns: </p>
  
  <pre><code>bash: ./ls: No such file or directory
  </code></pre>
  
  <p>But if I use gcc to link ls.o and ./lib/error.o together it works smoothly. So I wondered what's special in gcc's ld invoking. How do I do if I only use ld to link gcc produced stuffs? 
  Thanks beforehand! </p>