Create executable and shared library with one makefile
up vote
4
down vote
favorite
Using makefiles is new to me. My first tests with the simplest approach worked very well so far. But now I got stuck writing a makefile that creates a executable file and a shared library. As I said I'm new to makefiles. Here is my simple approach:
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
When the makefile is executed only the executable will be compiled. Is it even possible to create two objects with one makefile? What is the best approach to create these files?
compiling make executable shared-library
add a comment |
up vote
4
down vote
favorite
Using makefiles is new to me. My first tests with the simplest approach worked very well so far. But now I got stuck writing a makefile that creates a executable file and a shared library. As I said I'm new to makefiles. Here is my simple approach:
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
When the makefile is executed only the executable will be compiled. Is it even possible to create two objects with one makefile? What is the best approach to create these files?
compiling make executable shared-library
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
Using makefiles is new to me. My first tests with the simplest approach worked very well so far. But now I got stuck writing a makefile that creates a executable file and a shared library. As I said I'm new to makefiles. Here is my simple approach:
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
When the makefile is executed only the executable will be compiled. Is it even possible to create two objects with one makefile? What is the best approach to create these files?
compiling make executable shared-library
Using makefiles is new to me. My first tests with the simplest approach worked very well so far. But now I got stuck writing a makefile that creates a executable file and a shared library. As I said I'm new to makefiles. Here is my simple approach:
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
When the makefile is executed only the executable will be compiled. Is it even possible to create two objects with one makefile? What is the best approach to create these files?
compiling make executable shared-library
compiling make executable shared-library
edited Nov 24 at 1:25
Peter Mortensen
1,03821016
1,03821016
asked Nov 23 at 8:37
Olupo
235
235
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
5
down vote
accepted
By default make
will build only the first target in a Makefile
which is exe.a
in your case. You can either tell make
to create
another target:
make lib.so
or both targets:
make lib.so exe.a
or (preferred) introduce a new first target which is usually named
all
:
all: exe.a lib.so
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
Now a simple make
will build the (pseudo-) target all
which in turn
depends on exe.a
and lib.so
, so they get built first. Note that you
must not have a file called all
in your directory in this case because
then make
gets confused.
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter thisall
target very often.
– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
By default make
will build only the first target in a Makefile
which is exe.a
in your case. You can either tell make
to create
another target:
make lib.so
or both targets:
make lib.so exe.a
or (preferred) introduce a new first target which is usually named
all
:
all: exe.a lib.so
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
Now a simple make
will build the (pseudo-) target all
which in turn
depends on exe.a
and lib.so
, so they get built first. Note that you
must not have a file called all
in your directory in this case because
then make
gets confused.
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter thisall
target very often.
– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
add a comment |
up vote
5
down vote
accepted
By default make
will build only the first target in a Makefile
which is exe.a
in your case. You can either tell make
to create
another target:
make lib.so
or both targets:
make lib.so exe.a
or (preferred) introduce a new first target which is usually named
all
:
all: exe.a lib.so
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
Now a simple make
will build the (pseudo-) target all
which in turn
depends on exe.a
and lib.so
, so they get built first. Note that you
must not have a file called all
in your directory in this case because
then make
gets confused.
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter thisall
target very often.
– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
add a comment |
up vote
5
down vote
accepted
up vote
5
down vote
accepted
By default make
will build only the first target in a Makefile
which is exe.a
in your case. You can either tell make
to create
another target:
make lib.so
or both targets:
make lib.so exe.a
or (preferred) introduce a new first target which is usually named
all
:
all: exe.a lib.so
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
Now a simple make
will build the (pseudo-) target all
which in turn
depends on exe.a
and lib.so
, so they get built first. Note that you
must not have a file called all
in your directory in this case because
then make
gets confused.
By default make
will build only the first target in a Makefile
which is exe.a
in your case. You can either tell make
to create
another target:
make lib.so
or both targets:
make lib.so exe.a
or (preferred) introduce a new first target which is usually named
all
:
all: exe.a lib.so
exe.a: main.c func.c
gcc main.c func.c -o exe.a
lib.so: func.c
gcc func.c -o lib.so -fPIC -shared
Now a simple make
will build the (pseudo-) target all
which in turn
depends on exe.a
and lib.so
, so they get built first. Note that you
must not have a file called all
in your directory in this case because
then make
gets confused.
answered Nov 23 at 9:39
PerlDuck
4,95311230
4,95311230
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter thisall
target very often.
– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
add a comment |
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter thisall
target very often.
– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
Thank you. The option with the new first target is exactly what I was looking for.
– Olupo
Nov 23 at 9:49
@Olupo You are welcome. When you study other Makefiles you'll encounter this
all
target very often.– PerlDuck
Nov 23 at 9:51
@Olupo You are welcome. When you study other Makefiles you'll encounter this
all
target very often.– PerlDuck
Nov 23 at 9:51
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
I've read some other makefiles, but most of them were to advanced for my current skill level.
– Olupo
Nov 23 at 9:53
2
2
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
I know exactly what you mean :-) My skills aren't very good either and when it comes to more complicated Makefiles I usually think of them as rocket science.
– PerlDuck
Nov 23 at 10:04
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1095317%2fcreate-executable-and-shared-library-with-one-makefile%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown