Thread: Can anyone using mingw compile this?

  1. #1
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Post Can anyone using mingw compile this?

    Hi,

    in another post titled "Intel to AT&T Assembly" vVv replied to a problem I had with compiling the AT&T inline Assembly code translated from the Intel Assembly code that Fordy posted in response to another post.

    Yeah,

    I've been asking a lot of questions lately...

    He fixed the problem which would give gcc a hard time, but ...

    Since vVv is using FreeBSD, he's not getting the errors that I'm getting when trying to use mingw's port of GNU compiler tools (gcc, g++, etc.) with DevCPP (4, 4.9.7.8 beta 5, etc.) All of the correct commandline options are being passed, with and without optimization options.

    I'm still getting :
    undefined reference to `Hello1'
    undefined reference to `Hello2'
    A copy of the source is attached. This source has been modified from an Intel Syntax version, which is included at the bottom of the code in a comment block. Perhaps you'll spot something amiss...

    * A point I'd like to make: The original code which Fordy posted, using Intel Inline Assembly, cleanly compiles and works exactly as it should.

    Thanks for any help and/or viewing this post. I'm hoping to get my hands on a copy of cygwin to test it on that. If someone has good luck with that, please let me know.

    * Note: problem fixed. Download updated copy of source for details.
    Last edited by deoren; 03-18-2003 at 12:15 PM.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It doesn't compile under cygwin, with g++ (GCC) 3.2 20020927 (prerelease)

    Its moaning about the undef references to hello1/2.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    That's the problem with ASM and using compiler specific tools (like calling convention declarations).......not very portable....

  4. #4
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Works with ZipSlack 3.9's gcc

    One thing I haven't mentioned in this thread, which I did in another, is that this code will cleanly compile using g++ 2.7.3.2 under Slackware 3.9.

    As far as portability, I see your point... but ...

    Mingw is a windows port of gcc, so I was thinking that since we're not making any *NIX specific calls, commands, anything, it should work. Even with the gcc being mingw and not a *NIX version, it still uses the AT&T syntax, and seems to require a few different syntax changes, but should a large program ever need to be written for both OS's, a programmer could use

    Code:
     
    #ifdef WIN32
    #define INLINE_ATT
    #else
    #ifdef INTEL
    #define INLINE_INTEL
    or something like that. It would just require more code. At least I hope so! I'm not an expert by far, but I hope that sort of design would prevail, as I hope to learn enough to design for both "worlds".


    As far as this working for mingw or cygwin ...
    It's very close... I just can't figure out what the defining point of difference is...
    Last edited by deoren; 03-17-2003 at 11:43 AM.

  5. #5
    Registered User deoren's Avatar
    Join Date
    Mar 2003
    Posts
    63

    Exclamation It will now compile with newer mingw ports

    But...

    We're still getting a warning, and this time it looks like a C++ mangling problem.

    It still doesn't really see hello2, even when you call it with

    Code:
    asm 
       ( // using AT&T Assembly syntax here.  
    		"pushl szBuff;"   // ;push the param onto the stack
    		"call _hello1;"   // ;call the function
    		"addl $4, %esp;"  // ;restore the stack to previous state
    
    		"pushl szBuff;"  // ;push the param onto the stack
    		"call _hello2;"  // ;call the function 
    	    	// ;dont restore stack as hello2 will do that
     	);
    instead of

    Code:
    asm 
       ( // using AT&T Assembly syntax here.  
    		"pushl szBuff;"   // ;push the param onto the stack
    		"call hello1;"   // ;call the function
    		"addl $4, %esp;"  // ;restore the stack to previous state
    
    		"pushl szBuff;"  // ;push the param onto the stack
    		"call hello2;"  // ;call the function 
    	    	// ;dont restore stack as hello2 will do that
     	);
    The functions are declared as:

    Code:
    extern "C" void __cdecl hello1 (const char* szBuff)
    //force C calling convention
    {
    	std::cout << szBuff << std::endl;
    }
    and
    Code:
    extern "C" void  __stdcall hello2 (const char* szBuff)
    //force STDCALL calling convention
    {
    	std::cout << szBuff << std::endl;
    }
    In case you're wondering ... using the form below

    Code:
    extern "C" void  __stdcall hello2 (const char* szBuff)
    //force STDCALL calling convention
    {
    	std::cout << szBuff << std::endl;
    }
    vs. this

    Code:
    extern "C" void  __attribute__ ((stdcall)) hello2 (const char* szBuff)
    //force STDCALL calling convention
    {
    	std::cout << szBuff << std::endl;
    }
    is the same thing.

    The code once modified will compile on newer versions of mingw, specifically:

    mingw32 gcc 2.95.3-6
    mingw32 gcc 3.2

    with the warning:
    Warning: resolving _hello2 by linking to _hello2@4

    This version would not compile at all:
    mingw32 gcc 2.95.2

    Any ideas? It seems to be directly related to using stdcall for hello2, because when you take that calling convention "declaration" away, it compiles cleanly.

    Clifford Slocombe pointed out the need for prefixing the function names to be called in the assembly code. His post can be found at:

    http://sourceforge.net/forum/forum.p...forum_id=48211

    Thanks for everyone's help!

    Note: Problem fixed. For full details, view the source code or the above SourceForge DevCPP Forum link for full details.

    Basically, here is how it's supposed to be called:

    Code:
    asm 
       ( // using AT&T Assembly syntax here.  
    		"pushl szBuff;"   // ;push the param onto the stack
    		"call _hello1;"   // ;call the function
    		"addl $4, %esp;"  // ;restore the stack to previous state
    
    		"pushl szBuff;"  // ;push the param onto the stack
    		"call _hello2@4;"  // ;call the function 
    	    	// ;dont restore stack as hello2 will do that
     	);
    Once again, thanks for everyone's help!
    Last edited by deoren; 03-18-2003 at 12:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. mingw help
    By DarkDot in forum Tech Board
    Replies: 17
    Last Post: 04-16-2007, 11:25 PM
  2. .exe size with MinGW
    By Stabbsy in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2006, 06:07 AM
  3. compile prob: sched.h (win32 POSIX threads) - pid_t
    By BrianK in forum Windows Programming
    Replies: 6
    Last Post: 04-11-2003, 05:52 PM
  4. How can I compile C or C++ with Visual Studio .NET?
    By Dakkon in forum C Programming
    Replies: 8
    Last Post: 02-11-2003, 02:58 PM
  5. header file compile error
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 02-23-2002, 06:28 AM