Link to a thin archive on Snow Leopard

I am trying to link a thin archive that combines two archive libraries into a C program.

I built two simple hello world functions and built the archive using the commands:

ar rcs lib1.a lib1.o
ar rcs lib2.a lib2.o

Then the two archives are combined using a thin archive:

ar rcsT all_lib.a lib1.a lib2.a

and then compiled with gcc:

gcc main.o all_lib.a -o hello

As a result, an error message appears:

ld: warning: ignoring all_lib.a file, file was created for an unsupported file format that is not architecture related (x86_64)

Undefined characters for x86_64 architecture: "_func1" referenced: _main in main.o "_func2" referenced: _main in main.o ld: characters (characters) that were not found for x86_64 architecture

If I try to directly link main.o with lib1.a and lib2.a, everything will work.

gcc (MacPorts gcc46 4.6.3_3) 4.6.3 GNU ar (GNU Binutils) 2.21 Mac OSX 10.6.8.


Makefile

test1: main.o lib1.o lib2.o
    gcc main.o lib1.a lib2.a -o hello

test2: main.o combine
    gcc main.o all_lib.a -o hello

lib1.o: lib1.c
    gcc -c lib1.c
    ar rcs lib1.a lib1.o

lib2.o: lib2.c
    gcc -c lib2.c
    ar rcs lib2.a lib2.o

combine: lib1.o lib2.o
    ar rcsT all_lib.a lib1.a lib2.a

main.o: main.c
    gcc -c main.c

clean:
    rm -rf *.o  *.a hello

main.c

#include<stdio.h>
#include "lib1.h"
#include "lib2.h"

main()
{
    printf("Hello World\n");
    func1();
    func2();
}

lib1.h

#include<stdio.h>
void func1();

lib2.h

#include<stdio.h>
void func2();

lib1.c

#include "lib1.h"

void func1()
{
    printf("Hello World 1\n");
}

lib2.c

#include "lib2.h"

void func2()
{
    printf("Hello World 2\n");
}
+5
1

makefile Apple. , "-arch", "-arch x86_64" "-arch i386"?

"", , . .

-1

All Articles