3

I have the problem that I want to have a static library of my code because I use the code a lot. It's c++ (otherwise a shared would be an other choice). But that code depends on other static libs. Due to that I came to the point that I can't link a static library to an other. I found How to merge two "ar" static libraries into one. Due to that I tried a test, but it's not working and I want to know why and how to do it right.

I have two static libs each with a header(not linked but for implementation) and its source having a simple function return something. Lib1 has a function, lib2 has a function depending on lib1, and my executable 3.exe gets a linking error if I link lib1 and lib2. The function of lib1 is unreferenced. With the content of the link I wrote myself a batch-script which extracts all objects of a lib and quick adds it to the output lib:

@ECHO OFF

SET ar="C:\Programme\CodeBlocks\MinGW\bin\ar.exe"

FOR %%i IN (%1) DO SET SPath=%%~di%%~pi

cd \
cd D:
cd %SPath%

SET output="%SPath%output.a"
del %output%

:top
IF (%1) == () GOTO end

del "%SPath%*.o"
ar x %1
ar q %output% *.o

SHIFT
GOTO top

:end

del *.o

ar t %output%

script.bat libtest1.a libtest2.a

Its output looks reliable:

D:\
D:\CodeBlocks Workspace\lib test\*.o konnte nicht gefunden werden
ar: creating D:\CodeBlocks Workspace\lib test\output.a
main1.o
main2.o

Instead to lib1 and lib2 I linked to output but still the function of lib1 is unreferenced.

So what to do ? I don't want to include the whole code all the time.

Community
  • 1
  • 1
Joshua Behrens
  • 818
  • 13
  • 23

0 Answers0