1

I want to create static library and something goes wrong. I have makefile:

static: main.c tree.c
    gcc -c -Wall tree.c -o tree.o
    ar crs libtree.a tree.o
    gcc -Wall -static main.c -L. -ltree -o main
    ./main

When I write "make static", it shows me:

gcc -c -Wall tree.c -o tree.o
ar crs libtree.a tree.o
gcc -Wall -static main.c -L. -ltree -o main
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [static] Error 1

It created files: tree.o and libtree.a. I don't know why it doesn't want to find a library. Do you know how to solve it?

Euro Pe
  • 73
  • 2
  • 8

1 Answers1

0

Most probably, your system is not set up for static linking. Most newer Linux distributions aren't as static linking is highly discouraged.

Look for a package named glibc-static or similar and install.

In case your system is not Linux (could be MacOS X as well, you didn't state that) - You're doomed. Static linking is not supported on that platform at all.

tofro
  • 5,640
  • 14
  • 31