title: GCC insert a static library containing assembly into a dynamic lib
body: <p>I have a problem: I have 2 libraries (a static in ASM compiled with NASM and a dynamics in C compiled with GCC).</p>
  
  <p>I compile first the one in ASM with the following Makefile (I removed parts to make it more readable) :</p>
  
  <pre><code>ASM             =   nasm
  NAME            =   libasmlib.a
  SRC             =   [...all .asm files...]
  OBJ             =   $(SRC:.asm=.o)
  FLAGS           =   -f elf64 -g
  
  all             :   $(NAME)
  
  $(NAME)         :   $(OBJ)
                      ar rc $(NAME) $(OBJ)
                      ranlib $(NAME)
  
  %.o : %.asm
                      $(ASM) $(FLAGS) -o $@ $&lt;
  </code></pre>
  
  <p>Then I compile the dynamic library so that it uses the functions of the static :</p>
  
  <pre><code>CC                  =   gcc
  NAMEDYN             =   libclib.so
  SRC                 =   [...all .c files...]
  OBJ                 =   $(SRC:%.c=%.o)
  CFLAGS              =   -W -Wall -Werror -pedantic -fPIC
  LDFLAGS             =   -L./libs/ASM -lasmlib
  
  $(NAME)             :   $(OBJ)
                          $(CC) $(LDFLAGS) -shared -o $(NAMEDYN) $(OBJ)
  
  all                 :   $(NAME)
  </code></pre>
  
  <p>I have no problem, everything compiles perfectly but when I test the code with the following .c (with <strong><em>gcc maindyn.c -ldl</em></strong>) :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;dlfcn.h&gt;
  
  int                 main(int ac, char **av)
  {
      int             res;
      void            *handle;
      int             (*c_function)(char *str);
  
      if (!(handle = dlopen("./libclib.so", RTLD_LAZY | RTLD_GLOBAL | RTLD_NOW)))
          return 1;
      c_function = dlsym(handle, "c_function");
  
      res = c_function("Hi!");
      printf("%d\n", res);
      [...]
  }
  </code></pre>
  
  <p>I get this error :</p>
  
  <blockquote>
    <p>./a.out: symbol lookup error: ./libclib.so: undefined symbol: asm_function</p>
  </blockquote>
  
  <p>nm on the dynamic lib :</p>
  
  <pre><code>                 U asm_function
  0000000000202078 B __bss_start
  0000000000202078 b completed.7558
  &lt;snip&gt;
  0000000000000ee0 T c_function
  0000000000000e20 t register_tm_clones
                   U __stack_chk_fail@@GLIBC_2.4
  0000000000202078 d __TMC_END__
  </code></pre>
  
  <p>nm on the static lib :</p>
  
  <pre><code>asm_function.o:
  0000000000000000 T asm_function
  000000000000001c t _end
  0000000000000021 t _finded
  0000000000000008 t _loop
  </code></pre>