Make and apply apue.h
up vote
0
down vote
favorite
I started to learn APUE* and compile the source code
Download the source code from Source Code
Extract it to
$ pwd
/Users/me/Desktop/PubRepo/C/APUE/apue.3e
Read readme
$ cat readme
Read the file called DISCLAIMER.
On Freebsd, type "gmake".
On other platforms, type "make" (as long as this is gnu make).
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar@apuebook.com.
Steve Rago
January 2013
I checked
make
version
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
make but report error:
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE -c -o sleep.o sleep.c
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
make[1]: *** [getcputc] Error 254
make: *** [all] Error 1
I searched and found answer to add cp ./lib/error.c /usr/local/include/
$ cp ./lib/error.c /usr/local/include/
make clean and make
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [getcputc] Error 1
make: *** [all] Error 1
The error is still there.
How could I apply apue.h
?
* W Richard Stevens, Stephen A Rago
Advanced Programming in the Unix Environment, 3rd Edn, 2013.
c macos
add a comment |
up vote
0
down vote
favorite
I started to learn APUE* and compile the source code
Download the source code from Source Code
Extract it to
$ pwd
/Users/me/Desktop/PubRepo/C/APUE/apue.3e
Read readme
$ cat readme
Read the file called DISCLAIMER.
On Freebsd, type "gmake".
On other platforms, type "make" (as long as this is gnu make).
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar@apuebook.com.
Steve Rago
January 2013
I checked
make
version
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
make but report error:
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE -c -o sleep.o sleep.c
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
make[1]: *** [getcputc] Error 254
make: *** [all] Error 1
I searched and found answer to add cp ./lib/error.c /usr/local/include/
$ cp ./lib/error.c /usr/local/include/
make clean and make
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [getcputc] Error 1
make: *** [all] Error 1
The error is still there.
How could I apply apue.h
?
* W Richard Stevens, Stephen A Rago
Advanced Programming in the Unix Environment, 3rd Edn, 2013.
c macos
Why are you copying a.c
source file to/usr/local/include
?
– melpomene
Nov 10 at 6:11
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
You shouldn't copy a C source file to/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to usesudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file likeerror.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.
– Jonathan Leffler
Nov 10 at 7:16
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I started to learn APUE* and compile the source code
Download the source code from Source Code
Extract it to
$ pwd
/Users/me/Desktop/PubRepo/C/APUE/apue.3e
Read readme
$ cat readme
Read the file called DISCLAIMER.
On Freebsd, type "gmake".
On other platforms, type "make" (as long as this is gnu make).
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar@apuebook.com.
Steve Rago
January 2013
I checked
make
version
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
make but report error:
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE -c -o sleep.o sleep.c
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
make[1]: *** [getcputc] Error 254
make: *** [all] Error 1
I searched and found answer to add cp ./lib/error.c /usr/local/include/
$ cp ./lib/error.c /usr/local/include/
make clean and make
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [getcputc] Error 1
make: *** [all] Error 1
The error is still there.
How could I apply apue.h
?
* W Richard Stevens, Stephen A Rago
Advanced Programming in the Unix Environment, 3rd Edn, 2013.
c macos
I started to learn APUE* and compile the source code
Download the source code from Source Code
Extract it to
$ pwd
/Users/me/Desktop/PubRepo/C/APUE/apue.3e
Read readme
$ cat readme
Read the file called DISCLAIMER.
On Freebsd, type "gmake".
On other platforms, type "make" (as long as this is gnu make).
For FAQs, updated source code, and the lost chapter, see http://www.apuebook.com.
Please direct questions, suggestions, and bug reports to sar@apuebook.com.
Steve Rago
January 2013
I checked
make
version
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
make but report error:
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE -c -o sleep.o sleep.c
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: unable to execute command: Segmentation fault: 11
clang: error: linker command failed due to signal (use -v to see invocation)
make[1]: *** [getcputc] Error 254
make: *** [all] Error 1
I searched and found answer to add cp ./lib/error.c /usr/local/include/
$ cp ./lib/error.c /usr/local/include/
make clean and make
making intro
gcc -ansi -I../include -Wall -DMACOS -D_DARWIN_C_SOURCE getcputc.c -o getcputc -L../lib -lapue
ld: archive has no table of contents file '../lib/libapue.a' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [getcputc] Error 1
make: *** [all] Error 1
The error is still there.
How could I apply apue.h
?
* W Richard Stevens, Stephen A Rago
Advanced Programming in the Unix Environment, 3rd Edn, 2013.
c macos
c macos
edited Nov 10 at 7:14
Jonathan Leffler
558k896641016
558k896641016
asked Nov 10 at 5:51
avirate
654113
654113
Why are you copying a.c
source file to/usr/local/include
?
– melpomene
Nov 10 at 6:11
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
You shouldn't copy a C source file to/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to usesudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file likeerror.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.
– Jonathan Leffler
Nov 10 at 7:16
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21
add a comment |
Why are you copying a.c
source file to/usr/local/include
?
– melpomene
Nov 10 at 6:11
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
You shouldn't copy a C source file to/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to usesudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file likeerror.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.
– Jonathan Leffler
Nov 10 at 7:16
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21
Why are you copying a
.c
source file to /usr/local/include
?– melpomene
Nov 10 at 6:11
Why are you copying a
.c
source file to /usr/local/include
?– melpomene
Nov 10 at 6:11
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
You shouldn't copy a C source file to
/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to use sudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file like error.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.– Jonathan Leffler
Nov 10 at 7:16
You shouldn't copy a C source file to
/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to use sudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file like error.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.– Jonathan Leffler
Nov 10 at 7:16
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang
(using /usr/bin/gcc
is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db
subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc
or /usr/bin/clang
, you shouldn't need the CC=…
argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R.
argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include
for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include
.
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
add a comment |
up vote
0
down vote
There is an answer here from @makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I
tells gcc which directory to look for the include file. -L
tells it the location of the library directory, and -lapue
, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2fstackoverflow.com%2fquestions%2f53236356%2fmake-and-apply-apue-h%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang
(using /usr/bin/gcc
is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db
subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc
or /usr/bin/clang
, you shouldn't need the CC=…
argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R.
argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include
for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include
.
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
add a comment |
up vote
1
down vote
accepted
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang
(using /usr/bin/gcc
is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db
subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc
or /usr/bin/clang
, you shouldn't need the CC=…
argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R.
argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include
for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include
.
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang
(using /usr/bin/gcc
is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db
subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc
or /usr/bin/clang
, you shouldn't need the CC=…
argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R.
argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include
for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include
.
I downloaded the APUE source to a Mac running macOS 10.14.1 Mojave with XCode 10.1 installed (see also Can't compile a C program on a Mac after upgrade to Mojave).
I then ran make CC=/usr/bin/clang
(using /usr/bin/gcc
is also OK) to use that instead of a home-built GCC 8.2.0, which failed in the db
subdirectory. If you don't have any non-standard version of GCC installed on your PATH ahead of /usr/bin/gcc
or /usr/bin/clang
, you shouldn't need the CC=…
argument.
This did a lot of building — all of it successfully (once I'd specified the compiler explicitly; I got an error on the -R.
argument with the home-built GCC).
Make sure you have XCode properly installed. Worry about the Command Line Tools — see the "Can't compile" question for information on where to get them. You shouldn't need /usr/include
for this, but it is likely to make life easier; again, see the "Can't compiler" question for how to install /usr/include
.
answered Nov 10 at 7:32
Jonathan Leffler
558k896641016
558k896641016
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
add a comment |
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
ty, I drop xcode which consumed too much.
– avirate
Nov 10 at 7:53
add a comment |
up vote
0
down vote
There is an answer here from @makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I
tells gcc which directory to look for the include file. -L
tells it the location of the library directory, and -lapue
, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
add a comment |
up vote
0
down vote
There is an answer here from @makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I
tells gcc which directory to look for the include file. -L
tells it the location of the library directory, and -lapue
, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
add a comment |
up vote
0
down vote
up vote
0
down vote
There is an answer here from @makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I
tells gcc which directory to look for the include file. -L
tells it the location of the library directory, and -lapue
, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
There is an answer here from @makhlaghi that helped me a long time ago.
https://unix.stackexchange.com/questions/105483/compiling-code-from-apue.
Here is the answer that worked for me:
A short review of how to write and compile the programs in Advanced Programming in the UNIX® Environment, thanks to slm for helping me understand the steps. You can download the source code from here. I wish this information was included as part of appendix b of the book, where the header file is explained.
The uncompressed file contains directories with the names of the chapters and two others named include and lib. The ones with the names of the chapters have all the programs of that chapter in them.
The include directory contains the header file that is used in most of the programs in the book: apue.h. The lib directory has the source code of the implementations for the that header.
Lets assume the uncompressed file is located at: SCADDRESS/, for example it might be: /home/yourid/Downloads/apue.3e/
Once you uncompress the source code, go in the directory and run make:
$ cd SCADDRESS
$ make
make will compile all the programs in all the chapters. But the important thing is that before that, it will make the library that will contain the implementations of the functions in apue.h.
To compile an example program that you write from the book, run this GCC command (assuming your program's name is myls.c which is the first in the book):
gcc -o myls myls.c -I SCADDRESS/include/ -L SCADDRESS/lib/ -lapue
-I
tells gcc which directory to look for the include file. -L
tells it the location of the library directory, and -lapue
, tells the name of the library file to look for in that directory. Such that -LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
edited Nov 10 at 7:21
Jonathan Leffler
558k896641016
558k896641016
answered Nov 10 at 7:00
manoliar
12216
12216
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53236356%2fmake-and-apply-apue-h%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
Why are you copying a
.c
source file to/usr/local/include
?– melpomene
Nov 10 at 6:11
is it wrong? I followed a blog searched @melpomene
– avirate
Nov 10 at 6:14
You shouldn't copy a C source file to
/usr/local/include
, on principle. You shouldn't be able to do it because you'd need to usesudo
or something similar to get the necessary permissions/privileges. You shouldn't really even copy a header there, but definitely not a source file likeerror.c
. I'd recommend undoing that. I'd worry about whatever blog you got the information from.– Jonathan Leffler
Nov 10 at 7:16
ty, I am installing the Xcode to get a /usr/include dir.@JonathanLeffler
– avirate
Nov 10 at 7:21