-
gcc and -o -c
Im trying to make some small shared libs.
One of my C files needs 2 others, so i want to compile these 3 into a object file.
Heres what i get:
gcc -o str_move.o -c str_move.c str_remove.c str_insert.c
gcc: cannot specify -o with -c or -S and multiple compilations
make: *** [str_move.o] Error 1
What wrong? What should i do?
Thanks
-
Actually, a shared lib for those 2 deps was already made. How could I make gcc use them instead of compiling the code in?
-
is it not clear what you need but I'm sure you'd better to:
gcc -o str_move.o -c str_move.c
gcc -o str_remove.o -c str_remove.c
gcc -o str_insert.o -c str_insert.c
then link all togheter:
gcc -o executable str_move.o str_remove.o str_insert.o
in this way you build an executable, if you want a shared library to be build, you have to compile with fPIC (position independent code) and then link with some gcc link option (currently I do not have gcc man available)
tell me more about your problem
micio
-
you can't link .c files, they must be compiled into .o files, like micio said...and you need to tell us more about your predicament
Gentoo 2004.3 PPC Stage 2
500Mhz G3 Apple iBook
Slackware 10.0
AMD Athlon XP 1800+
-Jonathan Faulkenberry
-
It doesn't matter if "one c file needs another" because -c means you compile without linking. Everywhere in the str_move.o file where a function needs to call a function in str_insert.o is basically some sentence that says "Hey linker, when you link me make sure the function str_insert( ) is compiled somewhere with all of the object files you have to work with." Assuming you include str_insert.o in the list of parameters you pass to gcc when making and executable, when gcc does the linking it will find that function. If you don't include str_insert.o, it will claim there is an undefined reference to str_insert( ).
gcc -c str_move.c
gcc -c str_remove.c
gcc -c str_insert.c
ar r libstr.a str_move.o str_remove.o str_insert.o
ranlib libstr.a
For a static library
gcc -D_REENTRANT -fPIC -c str_move.c
gcc -D_REENTRANT -fPIC -c str_remove.c
gcc -D_REENTRANT -fPIC -c str_insert.c
gcc -shared -Wl,-soname,libstr.so.1 -o libstr.so.1.0.0 str_move.o str_remove.o str_insert.o
for shared
Last edited by grady; 10-20-2003 at 02:31 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|