Free Downloads, Community Forum,
FAQs and Developer Resources


Make /Tools Your Home | Link to us

Today's posts | Posts since last visit | Most Active Topics

All Forums Register Login Search Subscriptions My Profile Inbox
Tool Warehouse FAQs Resources Help Member List Address Book Logout

Building Posix application using Visual Studio 2005

 
Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [SFU / Interix / SUA Technology] >> Windows Server 2003 R2 SUA >> Building Posix application using Visual Studio 2005 Page: [1]
Login
Message << Older Topic   Newer Topic >>
Building Posix application using Visual Studio 2005 - Apr. 1, '06, 2:08:29 AM   
svpavlov

 

Posts: 2
Joined: Apr. 1, '06,
Status: offline
I have W2003R2 + SUA + Visual Studio 2005. SUA addin for Visual Studio support is installed. I try to make Posix application: take "Hello world" program, make VS project, go into its properties and set subsystem to Posix (Property Pages/Configuration Properties/Linker/System/SubSystem).

Problem #1: I cannot build project, linker complains to "unresolved external symbol ___PosixProcessStartup".

Well, I go to page (Property Pages/Configuration Properties/Linker/Input/Additional Dependencies) and add: crt0.o, psxlibc.lib, libpsxdll.a, libc.a, all from SUA directory (C:\WINDOWS\SUA\usr\lib\ on my system). Now executable can be built but

Problem#2: when running executable prints: "usage: posix /c <path> [<args>]" instead of "Hello, world!".

How can I build application for POSIX subsystem?
Post #: 1
RE: Building Posix application using Visual Studio 2005 - Apr. 2, '06, 6:04:44 PM   
jerker_back

 

Posts: 68
Joined: Jul. 7, '05,
From: Sweden
Status: offline
Hello svpavlov
I tried to figure this out in january - look at a posting in this forum in january 2006. I was rather confused about things back then and is only slightly wiser now. There is no info how to build posix apps with Visual Studio what I know of. Basically there's really no big deal and using Visual Studio should be pretty straightforward if just a few fundamentals are expressed.

My advise is:
1) Look how they do it in the cc script (/bin/cc). This is the only reliable source of information you have.
2) Start with a very simple program - your Hello world is surely fine.
3) Be sure to specify the following (I just give the command line switches, you'll have to find the corresponding entries in the property pages):
compiler (C/C++):
/D__INTERIX /D_ALL_SOURCE /D_REENTRANT /U_WIN32 (/D_IMPORT_LIBCDLL_GLOBALS)
/I$(SYSTEMROOT)\SUA\usr\include
/Zl /X /W4 /Z7 
Optional:
/Ox /Oi /Ot /Oy /Gy /GL /GF /EHsc /MT

Linker:
/LIBPATH:$(SYSTEMROOT)\SUA\usr\lib
/NODEFAULTLIB 
/SUBSYSTEM:POSIX
/ENTRY:__PosixProcessStartup
/MACHINE:X86 /DEBUG
libpsxdll.a libcsafe.a safecrt0.o 
- or -
libpsxdll.a psxlibc.lib crtexe.o

Optional:
/HEAP:8388608,32768 /STACK:4194304,65536
/OPT:REF /OPT:ICF /OPT:NOWIN98 /LTCG /RELEASE
/osversion:5.2 /ignore:4078

The app should run with no problem in an Interix shell. You also talk about the debugger addin. I never succeeded to get the addin to work - for me it says that there is no debugging info found. As debugging command I tried:
$(SystemRoot)\posix.exe /u /c /bin/ksh $(TargetFileName)


When porting, you will soon encounter some strange "unresolved external symbols" link errors. Annoying maybe, but as a general rule one should trust the compiler/linker - it is allmost always right. Some examples:
bsd_tar (FreeBSD libarchive-1.2.37 by Tim Kientzle)
_alldvrm
GNU make
_chkstk (_alloca_probe), _alloca_probe_8, _alloca_probe_16

These are internal runtime dependencies induced by the MS compiler/linker. The reason for the dependencies is that the linker expects to find the MS C runtime libraries (or NTDLL), which contains these objects. In Interix we have the BSD UNIX "libc" instead and it may not contain all the objects we need.

One way to solve this (I've tested this in several ways) is to recompile the MSCRT objects for use in Interix:
ml.exe /D_POSIX_ /X /I<mscrtpath> /coff /safeseh /W3 /Zi /Zp8 /Gd /Cx /c codefile.asm

where codefile.asm is the MSCRT assembler source file for the missing object. _POSIX_ defines 586 cpu, small model (same as _WIN32). If anyone have any comment on this, please make a posting. In fact, as _POSIX_ defines the same things as _WIN32 there should be really no problem to use the precompiled objects as is.

< Message edited by jerker_back -- Apr. 2, '06, 6:34:08 PM >

(in reply to svpavlov)
Post #: 2
RE: Building Posix application using Visual Studio 2005 - Apr. 3, '06, 6:22:37 AM   
svpavlov

 

Posts: 2
Joined: Apr. 1, '06,
Status: offline
Hi, jerker_back

Thank you very much for you detailed instructions!
Now I can build POSIX application from VisualStudio 2005. However I still cannot use VS debugger to debug POSIX application :( "Unable to start program" - says it...

(in reply to jerker_back)
Post #: 3
RE: Building Posix application using Visual Studio 2005 - Apr. 6, '06, 5:33:33 AM   
mduft

 

Posts: 15
Joined: Nov. 16, '05,
Status: offline
Hey!

I had similar problems debugging applications with visual studio (2003 and 2005) i was wanting to debug applications built native win32 with wgcc (sourceforge) which i wrote myself (the compiler). the problem is, that even when the executeable is debugable, it has to have an extension, which can be anything, not just .exe. Otherwise visual studio complains about no debug info found. just renaming the file to something with an extension (file.a or file.exe or ...) helps, and debugging works fine...

when debugging posix executables with vs 2005 (2003 doesn't work) just start with devenv.exe /debugexe ... -> this worked fine for me! it automatically loads posix.exe and reaches through it to the debugging exe... (you need the debug plugin for this ;o))

Regards, Markus

(in reply to svpavlov)
Post #: 4
RE: Building Posix application using Visual Studio 2005 - Apr. 7, '06, 12:49:49 PM   
jerker_back

 

Posts: 68
Joined: Jul. 7, '05,
From: Sweden
Status: offline
Hello Marcus
Can you explain in more detail how you used the debugger?
I tested the debugger just as one would do normally with ordinary WIN32 programs, then I started to change the debugger command - no luck - "no debug info found".
Is the secret just to rename the output to have [what] extension?

(in reply to mduft)
Post #: 5
RE: Building Posix application using Visual Studio 2005 - Apr. 10, '06, 2:32:25 AM   
mduft

 

Posts: 15
Joined: Nov. 16, '05,
Status: offline
Hey there!

Ok, heres step by step:

My test prgram is:

#include <stdio.h>

int main(void)
{
    printf("Hello Windows Debugger!\n");
    return 0;
}


This piece of code needs to be compiled with the windows compiler or a tool that uses the windows compiler, (and for VS.NET 2003 -> one that does NOT create an executeable that uses POSIX.EXE!!). For vs 2003 i'm using wgcc here (www.sourceforge.net/projects/interix-wgcc -> when building wgcc, be sure to have your visual studio paths set!! Look at wgcc.conf in the etc/ directory of your installdir and check if the paths are ok.)

Compile with debug info (i.e. with -g):

wgcc -g -o test.exe test.c


this gives:

drwxr-xr-x  1 mduft  Domõnen-Benutzer       0 Apr 10 08:21 .
drwxr-xr-x  1 mduft  Domõnen-Benutzer       0 Apr 10 08:16 ..
-rw-r--r--  1 mduft  Domõnen-Benutzer      88 Apr 10 08:17 test.c
-rwxr-xr-x  1 mduft  Domõnen-Benutzer   94208 Apr 10 08:21 test.exe
-rwx------+ 1 mduft  Domõnen-Benutzer  468232 Apr 10 08:21 test.ilk
-rwx------+ 1 mduft  Domõnen-Benutzer  355328 Apr 10 08:21 test.pdb


Now simply start the debugger with:
(You need to be sure to have Visual Studio Directories in your path!)

devenv.exe /debugexe test.exe


Open the source file test.c and set a breakpoint at the printf statement. Then simply start debugging by pressing F5 (if using c++ 6 keyboard layout). Visual Studio will create a .sln and a .suo file to save your "options" (lol). hmmm. Now it will break at the breakpoint. In Visual Studio 2005 debugging with posix.exe is not possible, except when you attach to a running process...

You may build an endless loop at the start of your main, start the programm from outside visual studio, and then attach the that process and jump out of the loop. This has worked for me too. just be sure, the executeable has an extension.

With Visual Studio 2005, when the Plugin is installed you may use cc or c89 or wcc instead of wgcc. The Plugin makes Visual Studio able to reach through POSIX.EXE to your code.

I hope this helps and is correct (and i didn't forget something) ;o)

I had no visual studio 2005 / interix 5.2 combination available today, so i couldn't test it now, but it worked some time ago for me...

Regards, Markus

(in reply to jerker_back)
Post #: 6
RE: Building Posix application using Visual Studio 2005 - Apr. 23, '06, 12:09:15 PM   
jerker_back

 

Posts: 68
Joined: Jul. 7, '05,
From: Sweden
Status: offline
The VSDebugger beats me - I just can't get it to work
First I couldn't find it on my system, then looking in the registry I finally found where it is installed:
%ALLUSERSPROFILE%\Application Data\Microsoft\MSEnvShared\Addins

Am I sure it is properly installed?
No - this is managed Addin with a private installation procedure - no public tools can check the installation.

Asuming it really is working as it should, how to use it?
Help_and_releasenotes.doc white paper
quote:


You can start debugging in one of the following two ways:

1. Start the program from within Visual Studio by pressing F5 inside a Visual Studio session. Start Visual Studio 2005 and click File, Open, and then Project/Solution, or enter devenv.exe <exe> or devenv.exe /debugexe <exe> <args> at a VS prompt or into an open Korn shell.
2. Attach to an active process by clicking Attach to Process on the Tools menu Oruse command VSJITDebugger.exe –p <PID> where PID is process id shown in task manager (Windows PID).

Explains everything? Pressing F5 must be the same as enter the usual "Start debugging" command, or? Anyway, it all ends up the same way: A dialog "No Debugging Information" with the content: "Debugging information for 'posix.exe' cannot be found... Do you want to continue debugging?". In the background I see a disabled dialog: "PosixPID(NativePID)[EXE Path]". Pressing yes just executes the program and exits. I also tried "Step into" (F11) and "Run to cursor" - same result.

Setting a breakpoint doesn't help either ... ??? - strange things happens - when writing this the debugger actually starts to work! The disabled dialog shows my app and the apps output is written to a console window "posix.exe". I can now walk trough the code line by line and evalute all variables - great!
So what did I do?
* I set a breakpoint at the first line in main().
* I used "Run to cursor" at the first line in main()

The secret appears to be setting a breakpoint to get it all working

(in reply to mduft)
Post #: 7
Page:   [1]
All Forums >> [SFU / Interix / SUA Technology] >> Windows Server 2003 R2 SUA >> Building Posix application using Visual Studio 2005 Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Search All Forums -

Advanced search


SPONSORS



Forum Software © ASPPlayground.NET Advanced Edition 2.5 ANSI

0.047