Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
87 user(s) are online (69 user(s) are browsing Forums)

Members: 0
Guests: 87

more...

Support us!

Headlines

 
  Register To Post  

C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
Hello,

I'd like to know if it can be possible to compile a C/C++ source code ton create some sort of libraries that may be used from C/C++ ?
And that should be included in our source code as object or directly by the compiler ...

Thanks

Kindest Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@freddix

you can create what is called a "static library" out of any number of .o (under SAS/C files were having .lib extension, under GCC files are named libxxx.a) by using the command line program 'ar' (see manual page here)

EDIT: creation of an Amiga Shared library ( xxx.library) is a bit more complicated (but not inacessible) and requires some specific code.

Back to a quiet home... At last
Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@abalaban
Thank you for this information.
I actually does not need to create .library files. I need .o or .a files like you said seem fit my needs.

Can it contain without including, references to other .o .a files ? (for example a pack of .a files with one that is the setup and the other ones that must include it on compilation to work). Possible ?

Thank you.

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C/C++ compile to .o ... .lib ?
Just popping in
Just popping in


See User information
@freddix

In a .a file, you can reference .o files listed previously in the linking order. Order is significant when developing linker libraries.

Likewise when linking .o files, any one that references another one must be linked AFTER the one that it references.

Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@freddix

to compile against a .a file you have to add a specific option to the compiler. For example to link with libauto.a
you'll add "-lauto" at the en of the link command line (the one that links all object files *.o into your executable).
As Samurai_Crow said you can of course have one .a file referencing function from another one, *but* then you'll have to be very carefull about the order of them.
For example if libclient.a uses some function from libserver.a you'll have to link with libclient *before* libserver like that
gcc -o myexe oneobject.o anotherobject.-lclient -lserver

Back to a quiet home... At last
Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@abalaban
ok.
I understand.

But, how can I make a .a file try to use a function available within another .a file ... which command should I use ?

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C/C++ compile to .o ... .lib ?
Not too shy to talk
Not too shy to talk


See User information
@freddix

you must use the command 'ar'
like stated by abalaban in the first reply

Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@abalaban
Quote:

creation of an Amiga Shared library ( xxx.library) is a bit more complicated (but not inacessible) and requires some specific code.


There's an option to make it shared without special code as .so file.
But I think (please correct me if I'm wrong) it isn't shared in the way .library is (each app that loads .so file will have own copy of the code loaded into memory).

Jack

Resized Image
"the expression, 'atonal music,' is most unfortunate--it is on a par with calling flying 'the art of not falling,' or swimming 'the art of not drowning.'. A. Schoenberg
Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@Jack

I mean inside C code.
When I code my .a file ... if I want my code to look into another .a file ... should I simply add the .a file in the compiler or is there a command like that in C:
file = open.a( filename )

Regards,
Fred

All we have to decide is what to do with the time that is given to us.
Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@freddix

Just add the .a file you want to the linker command.
Examples:

say you have something.a archived from some .o files and you want to link it in:

to create .a:
gcc -c fun1.c
gcc -c fun2.c
gcc -c fun3.c
delete somthing.a
ar q something.a fun1.o fun2.o fun3.o
ranlib something.a

to link your code with something.a
gcc mycode.c somethng.a -o myapp

or more comlex code:
gcc -c mycode1.c
gcc -c mycode2.c
gcc mycode1.o mycode2.o something.a -o myapp

And as mentioned above: order is important. Afair, in case of multiple instances of the same function, the first one is linked in.


I hope this helps
Jack

Resized Image
"the expression, 'atonal music,' is most unfortunate--it is on a par with calling flying 'the art of not falling,' or swimming 'the art of not drowning.'. A. Schoenberg
Go to top
Re: C/C++ compile to .o ... .lib ?
Just popping in
Just popping in


See User information
@freddix

To use multiple .a files together, the one that depends on the routines in the other one should be listed LAST. You don't need to open or close a .a file because it is all processed before the program runs. It is handled by the linker after the compiler but before the executable is run. Only .library files need to be opened at runtime.

Go to top
Re: C/C++ compile to .o ... .lib ?
Quite a regular
Quite a regular


See User information
@freddix

As I said in my first post, .a files are 'static' libraries as such they are linked in your program making it bigger contrary to Amiga shared libraries that can be loaded at the point the program needs it (and closed immediatly after that).

Using a function from a static library (or archive) is easy and it's like using a function from another .o : you should have an header (.h) with the function prototype, then you can use the needed function in your code, and last you add it to the link command line in your makefile.
For example, let's say i'd like to use function pthread_create from libpthread.a (SDK:local/newlib/lib/libpthread.a) I'll have to include it's header (SDK:local/common/include/pthread.h) using
#include <pthread.h>
(SDK:local/common/include/ is a system path and GCC look into it automatically)
then at link stage you add -lpthread to the command line like that :
ppc-amigaos-gcc -o MultiThreadedExe $(OBJ) -lpthread

That's all.
Please note that as Jack mentionned you can directly add your .a file(s) amongst your .o files, but then there is not so much interest in building a .a file. When you build your own library which thus is not placed into a standard system path, you should instruct GCC where it should look for your library by adding -Lpath on the command line for example let's say you built your own library named libDark3D.a and which is placed in a subdir named myLibs of your current directory, you'll write something like that :
ppc-amigaos-gcc -o progTest mainTest.o another.-LmyLibs -lDark3D


@Samurai_Crow

This is the reverse code using function *before* code providing function.

Back to a quiet home... At last
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project