In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use autoconf to generate Makefile and compile the project, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Steps
Install autoconf first
Sudo apt-get install autoconf
Create a new project folder (for example: 喜悦)
Mkdir 喜悦
Cd 喜悦
Create two new folders lib and src in it to put the library files and source files of the project.
Mkdir lib
Mkdir src
As shown in the following figure:
Go to the lib folder, create a new header file, such as .h, and casually declare a function.
Cd lib
Gedit .h
/ / .h#include void print ()
Go to the src folder, create a new C file, such as .c, realize the function of the header file; create a new C file, such as main_code.c, and write the main function.
Cd.. / src
Gedit .c
/ / .c#include ".. / lib/.h" void print () {printf ("\ n");} / / main_code.c#include ".. / lib/.h" void main () {print ();}
Going back to 喜悦 's folder, our engineering documents have been written.
Cd..
Run autoscan to generate configure.scan
Autoscan
Edit configure.scan
Gedit configure.scan
# Edit the original file before #-*-Autoconf-*-# Process this file with autoconf to produce a configure script.AC_PREREQ ([2.69]) AC_INIT ([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS]) AC_CONFIG_SRCDIR ([src/.c]) AC_CONFIG_HEADERS ([config.h]) # Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures And compiler characteristics.# Checks for library functions.AC_OUTPUT
The prefix AC refers to AutoConf
Don't worry about AC_PREREQ.
Fill in [package name] [version] in AC_INIT [BUG submission address is your email address]
Fill in any file name under the source file path in AC_CONFIG_SRCDIR. Autoconf checks whether the file exists and determines whether the path is correct. Generally, it doesn't matter.
Don't worry about AC_CONFIG_HEADERS.
Insert the following sentence, which is required in the automake phase, otherwise an error will be reported.
AM_INIT_AUTOMAKE
The prefix AM refers to AutoMake
The modified file is as follows:
# modified file #-*-Autoconf-*-# Process this file with autoconf to produce a configure script.AC_PREREQ ([2.69]) AC_INIT (hhh, 1.0, idontknow@666.com) AC_CONFIG_SRCDIR ([src/.c]) AC_CONFIG_HEADERS ([config.h]) AM_INIT_AUTOMAKE # Checks for programs.AC_PROG_CC# Checks for libraries.# Checks for header files.# Checks for typedefs, structures And compiler characteristics.# Checks for library functions.AC_OUTPUT (Makefile)
Save and rename configure.scan to configure.ac
Create a new Makefile.am
Gedit Makefile.am
Enter the following code
AUTOMAKE_OPTIONS=\ foreign\ subdir-objectsbin_PROGRAMS=test_prj test_prj_SOURCES=\ lib/.h\ src/.c\ src/main_code.c
AUTOMAKE_OPTIONS is followed by the execution option of automake, separated by spaces
Subdir-objects means that compiled .o files can be placed in a subpath (along with the source file). Without this option, all .o files will be placed in the project root directory.
The name after bin_PROGRAMS is the generated executable binary file name
You can have multiple bin_PROGRAMS, but each bin_PROGRAMS needs to have a corresponding xxx_SOURCES
Xxx_SOURCES is a dependency of the executable file xxx, including header files, source files, etc.
Generate aclocal.m4 file with aclocal
Aclocal
Generate configure file with autoconf
Autoconf
Using autoheader to generate config.h.in
Autoheader
To generate Makefile.in with automake, you need to add-add-missing to automatically add the default file
Automake-add-missing
Then our software is done, and the whole package can be uploaded to github or open source forum.
How do you compile the link executable file after someone downloads our source package? Or how do we compile and link our executable files?
The following are the general steps for the source code installation and the steps for us to compile the link
Generate Makefile first
. / configure
And then make
Make
Now we can see that the executable file test_prj has been generated
The result is correct.
When we enter the src directory, we find two more files
This is what subdir-objects does in AUTOMAKE_OPTIONS. Without this sentence, these two .o files will appear in your root directory. If it is unfortunate that your project is relatively large and has a file of the same name, it may have very serious consequences, so this sentence is suggested to be added.
The above is all the contents of the article "how to use autoconf to generate Makefile and compile a project". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.