This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: detecting program invocation from a symbolic link


On Thu, Apr 23, 2009 at 02:42:09PM -0700, ncokwqc02@sneakemail.com wrote:
>The result is apparently compiler dependent.
>
>Here's some simple test code:
>
>        #include <iostream>
>        int main(int, const char** argv)
>        {
>                using namespace std;
>                cout << "Hello World, I was called from " << argv[0] << endl;
>                return 0;
>        }
>
>I build this code to create an executable named
>        test_sym_link.exe
>using the MS Visual Studio C++ compiler, the Intel C++ compiler, the
>Metrowerks Codewarrior C++ compiler, and the g++ compiler that came
>with Cygwin.
>
>Then I create a symbolic link like this from a Cygwin shell
>        $ ln -s test_sym_link.exe new_file
>which produces the following directory entry
>        $ ls -l new_file
>        lrwxrwxrwx 1 ottusch None 17 Apr 23 13:39 new_file -> test_sym_link.exe
>as expected.
>
>If I run the program as built using any of the compilers other than g++ I get
>        $ ./new_file
>        Hello World, I was called from C:\Documents and Settings\ottusch\test_sym_link.exe
>which, of course, is also what I get if I run ./test_sym_link
>
>Only in the case where the compiler is g++ do I get
>        $ ./new_file
>        Hello World, I was called from ./new_file
>which is the desired, Unix-like, result.
>
>These results were all obtained while working from a Cygwin console.
>The symbolic link 'new_file' shows up as 'new_file.lnk' in a Windows
>command prompt shell and I don't know how to execute it directly from
>the command line.
>
>Nice that it works with g++ but I need this to work with the other
>compilers too.  Any suggestions?

You really do need to use Cygwin programs to understand Cygwin features.
This should not be overly surprising.

There isn't any straightforward way to make this work with non-Cygwin
programs.  It is theoretically possible to get Cygwin's argv list via
the cygwin_internal CW_ARGV call but that would involve dynamically
loading cygwin1.dll which has its own set of problems.

cgf

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]