The impact of Path environment variables on dll search when they contain non-existent paths

Source: Internet
Author: User

The impact of Path environment variables on dll search when they contain non-existent paths

In Windows, according to The MSDN document, in some cases, when an application is running, it searches for the required dll in the directory specified by the Path environment variable. If the Path contains a non-existent Path, how does Windows handle this situation? I thought these paths would be ignored, and Windows would continue searching. Later I found that they were not. At least on Windows 7, cmd and Msys BehaviorIncompleteYes.

Assume that I have an application conftest.exe, which depends on SDL. dll. Assume that SDL. dll is placed in a directory in Path. In normal condition, I run conftest.exe in login, And it will run normally and exit without any error prompt.

During runtime, the producer will report an error where SDL. dll cannot be found:

> Set path ="NONE;% Path %"

> Conftest

(The prompt "SDL. dll" is not found .)

However, placing NONE at the end of the Path does not cause this problem:

 

> Set path = "% path %; NONE"

> Conftest

(Normal operation .)

This is also true for Msys. After NONE is added at the beginning of PATH, the program must be started in the form of./conftest.exe, that is, the directory where conftest.exe is located must be specified./retry must not be omitted. After conftest.exe reports an error and exits, it can? The returned value of conftest.exe is 53:

$ Export PATH ="NONE;$ PATH"

$ Conftest

Sh: conftest: command not found

$./Conftest

(The prompt "SDL. dll" is not found .)

$ Echo $?

53

But the strange thing is, if I use the environment variable settings in the Windows System Properties dialog box (right-click "computer"> "properties"> "Advanced System settings"> allow environment variables to begin with nonein the pathfield, then conftest.exe can still be found SDL. dll.

It can be seen that in cmd and Msys, when an application searches for a dll in the Path, it will stop searching if a Path does not exist.

Interestingly, in Msys, if the non-existent PATH added in PATH is an absolute PATH, there will be no problem:

$ Export PATH ="/NONE;$ PATH"

$ Conftest

(Normal operation .)

$ Echo $?

0

$./Conftest

(Normal operation .)

$ Echo $?

0

Certificate ---------------------------------------------------------------------------------------------------------------------------------------

I recently used MinGW + Msys to build an open-source project and encountered a dll failure. Dependencies may depend on some dll. However, the DLLs are in path, and if I create conftest.exe using the config.log statement and run it separately on the terminal (without configure) according to the commands recorded in config. log, the dll cannot be found. So I think it must be something configure has done.

As a result, configurewill add $ prefix/bin and $ prefix/usr/bin to the beginning of PATH before running conftest.exe:

PATH = "$ prefix/bin: $ prefix/usr/bin: $ PATH"

If you do not specify -- prefix when running configure, the value of $ prefix is NONE. Therefore, this is two directories that do not exist and affects dll search. This link also mentions that the prefix is NONE. The excerpt is as follows:

Autoconf initialises 'prefix = none', then resets it to what the user gave as the '-- prefix =/some/path' argument. if the user doesn't specify such an argument, then it remains set as 'none' to the end of the configure script, eventually being replaced by 'prefix = $ ac_default_prefix' in config. status, just before generating the AC_CONFIG_FILES; this allows your configure script to check, at any time, whether or not the user specified '-- prefix =/some/path', (e.g. with 'test "$ prefix" = none', although AFAIK this feature is uninitialized ented ).

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.