0

Recently I wanted to build a game engine using C++ and glfw3. I want to create a static library libengine.a and link it with libglfw3.a and its dependencies. My question is how can I replace this:

# add paths. use pkg-config --static --libs glfw3 to 
# find libraries for your specific system
glfw_libs:=\
        /usr/local/lib/libglfw3.a\
        /usr/lib/x86_64-linux-gnu/librt.a\
        /usr/lib/x86_64-linux-gnu/libm.a\
        /usr/lib/x86_64-linux-gnu/libdl.a\
        /usr/lib/x86_64-linux-gnu/libX11.a\
        /usr/lib/x86_64-linux-gnu/libpthread.a\
        /usr/lib/x86_64-linux-gnu/libxcb.a\
        /usr/lib/x86_64-linux-gnu/libXau.a\
        /usr/lib/x86_64-linux-gnu/libXdmcp.a

lib:= $(glfw_libs)
...
...
$(library): $(obj)
    ar rs $@ $^ $(lib)

with something like this:

glfw_libs:=/usr/local/lib/libglfw3.a\
        -lrt -lm -ldl -lX11 -lpthread -lxcb -lXau -lXdmcp

lib:= $(glfw_libs)
...
...
$(library): $(obj)
    ar rs $@ $^ $(lib)
Ðаn
  • 10,934
  • 11
  • 59
  • 95
Dragomir
  • 43
  • 1
  • 6
  • See [this post](https://stackoverflow.com/questions/8170450/combine-static-libraries) – alteredinstance Jan 16 '20 at 18:37
  • Does it not work if you simply remove the `lib:= $(glfw_libs)` line, and replace the list of explicit names with the `-l` names and you're done? If you're happy to list `-lXdmcp` on the command line, you aren't really looking to build a single library contain that and all the others, which is A Good Thing™. You could probably list `-lglfw3` too; there's a good chance that the compiler (linker) looks in `/usr/local/lib` anyway. – Jonathan Leffler Jan 16 '20 at 18:42
  • No, it does not because ar complains about -llibname it says unknown option so I had to use full names but I am not satisfied with that approach and could not find anything related to this problem – Dragomir Jan 16 '20 at 19:05

0 Answers0