How to debug configure during program Compilation

Source: Internet
Author: User
How to debug configure during program Compilation Source:
Ibm dw China

Author:
Peter seebach
Time:
2007-04-22
Click:

[Add to favorites
] [Contribution
]

But the test program mistakenly considers the function missing.

Whenautoconf
When the target is a mainstream platform (especially a variety of Linux, but also the main Unix release versions), there are very few bugs to test, such bug tests are usually the results of running tests on platforms or compilers that have not been widely tested. For examplegcc
No previous bugs will occur. This occurs only when the system development kit is used for compilation. The simplest solution isconfigure
Comment out the corresponding test and directly set the problematic environment variable.

The compiler does not really work.

Sometimesconfigure
The compiler flag selected in the previous stage can link the executable file, but the generated executable file cannot run. This is a particularly fatal error. This will cause the test to fail for no reason. For example, if the linker command you are using is incorrect, you may be properly linked, but cannot run it. By the time this article is completed,configure
This error cannot be found in the script, so only the tests that require the target program to run will report the failure. This is incredible for debugging, but you can use the config. Log script to figure out what went wrong. For example, in a test system, I got the following output:

Listing 5. Test config. log output

 
configure:5644: checking for working memcmp
configure:5689: gcc -o conftest -g -O2 -fno-strength-reduce
-I/usr/X11R6/include -L/usr/X11R6/lib conftest.c -lXaw -lXext
-lSM -lICE -lXmu -lXt -lX11 -lcurses >&5
configure:5692: $? = 0
configure:5694: ./conftest
Shared object "libXaw.so.7" not found
configure:5697: $? = 1
configure: program exited with status 1

 

The real error is that the compiler requires a separate flag to tell it that/usr/x11r6/lib needs to appear in the search directory list so that the dynamic link library can be found at runtime. In any case, this is the first such test. It actually runs the compiled test program, rather than stops after the program is compiled successfully. This is a very subtle problem.

In this system, the solution is to add

-Wl,-R/usr/X11R6/lib

ToCFLAGS
Variable. Command line:

$ CFLAGS="-Wl,-R/usr/X11R6/lib" ./configure

Allowconfigure
Run the test correctly.

This is especially detrimental to cross-compilation because you may not be able to run executable programs created by the cross compiler. Recentautoconf
All versions should try to avoid testing that requires the testing program to actually run.

Find the missing library and include

Another common problem with using configure scripts is that if a specific software package is installed in an unconventional location,configure
It cannot be found. Okay.configure
Scripts usually allow you to specify the path of the required files, because they may be installed in a different location. For example, manyconfigure
The script uses a standard method to tell the script where to find the X Library:

Listing 6. Search for database x


X features:
--x-includes=DIR X include files are in DIR
--x-libraries=DIR X library files are in DIR

 

If this still does not work, you can also try to use the fully forced method: specify the required compiler to mark as yourCC
Environment variable orCFLAGS
Environment variable.

Other skills

If the developer givesautoconf
Used to generateconfigure
Scriptconfigure.in
File, a workspace will run the latest versionautoconf
. This is possible, but it can solve some problems even if it cannot work well. The purpose of this operation is to update the specific test used.configure
It may be a bug that causes problems. In this case, if you are a developer in this situation, you must releaseconfigure.in
File.

If you need to adjustconfigure
And you are not good at shell command line editing, you can make a package script, this script is called with appropriate parametersconfigure
. After some adjustments and some failed tests, your script may be like this:

Listing 7. Package script


./configure --with-package=/path/to/package /
--enable-widget /
--disable-gizmo /
--with-x=29 /
--with-blah-blah-blah
CFLAGS="-O1 -g -mcpu=i686 -L/usr/unlikely/lib /
-I/usr/unlikely/include -Wl,-R/usr/unlikely/lib"

 

Compared to entering the script over and over again in the command line, it is easy to put the script together-and you can reference it later, or send a copy of it to someone else.

Develop robust configure scripts

One point of prevention is better than a very good treatment. To enableconfigure
The best way for a script to work is to make sure it does not make any mistakes when generating it.

When you try to build a robustconfigure
The script is actually very simple. Never test what you don't really need. Do not testsizeof(char)
Because in Csizeof
Returns an object of the character size to save some content,sizeof(chare)
Always 1 (even on those machines with more than 8 characters ). In most cases, there is no reason to test whether you have the right to use
Whether functions in ANSI/iso c or standard C header files are available. What's worse is to test non-standard features when standard features exist. Do not test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.