Solved

ilink32 error

Posted on 2004-10-23
857 Views
Last Modified: 2012-08-13
Hi programmers,
Please,look at the following program:
.386
Locals
jumps            
.model flat,stdCall;
mb_ok     equ 0
hWnd      equ 0  
lpText    equ offset text
lpCaption equ offset caption

extrn     ExitProcess   :proc
extrn     MessageBoxA   :proc

DATA segment use32 public
  text     db "Happy new academic year",13,10
caption  db "Hello Students",0,'$'
DATA ends
code segment use32 public
 start:
        push mb_ok
        push lpCaption
        push lpText
        push hWnd
        call  MessageBoxA
        CALL  ExitProcess
code ends
End start
Assembling this program with tasm32 is ok, but the linker, ilink32, displays the following fatal error: "...additional segment need to be defined in a .DEF file"
Who can explain and solve this error, especially, what is a DEF file ?
Only a profound explanation will be accepted.
Thanks in advance,
xyoavx
0
Question by:xyoavx
    10 Comments
     
    LVL 9

    Accepted Solution

    by:
    Your problem actually caused by segment definition, there is no any 'CODE' segment in your code.
    you have two choices,
    1. change "code segment use32 public" to "code segment use32 public 'CODE'"
       Although you wrote this line,  code segment use32 public, but this line hasn't define the classname of the segment, so assembler just treat it a data segment
    2. usually we write the segment like this: we use .data and .code to define the segments
    .DATA
            text     db "Happy new academic year",13,10
          caption  db "Hello Students",0,'$'
    .code
     start:
            push mb_ok
            push lpCaption
            push lpText
            push hWnd
            call  MessageBoxA
            CALL  ExitProcess
    End start

    3. .DEF file is called Module-Definition (.DEF) Files, you can search "Module-Definition (.DEF) Files" from MSDN, if you ever coded with SDK you should know it, it can define version, description, export functions...etc., but for now, most IDEs have hide this file, you even don't need to know it. Here is a example:
    LIBRARY            YourProgName

    EXPORTS
                yourexportedfunctions
                foo
    SECTIONS
                segname      READ WRITE SHARED EXECUTE
    You can see that the .def file also can change the property of any segment, this technology always used by some programs which will change their code dynamically, such as some exe encryptor or packer.
    Your linker reported "...additional segment need to be defined in a .DEF file", I think that's because the linker hasn't found any CODE segment, but on my machine, my linker(tasm 5.0) hasn't reported the same error, actually it hasn't reported any error, but the exported exe file hasn't any import table, so we can't run it properly. So I think you also can fix your problem with the .def file, you may can override your code segment to executable and set it to 'CODE' segment, but I have no time to test it...

    Hope this can help you.


    0
     
    LVL 11

    Assisted Solution

    by:dimitry
    To add to BeyondWu answer:
    You can use different names for segments. For example next code is doing what you want:
    --------------------------------------------------------------------------------------------------------
    ideal
    p386
    model flat,stdCall,nt

    mb_ok     equ 0
    hWnd      equ 0  

    procdesc MessageBoxA :dword, :dword, :dword, :dword

    const
      mytext   db "Happy new academic year",13,10,0
      caption  db "Hello Students",0,'$'

    codeseg
    start:
      startupcode
      call  MessageBoxA, hWnd, offset mytext, offset caption, mb_ok
      exitcode
    End
    0
     

    Author Comment

    by:xyoavx
    Hi programmers,
    Thanks for your comments.
    I would like to ask you the following questions:
    1. Where did you get the information, included in your answers ? books ?, articles ?,
        manuals ?, trial and error ? Please, answer.
    2. The box, displayed by the above programs, is accompanied by a dos window. How    
        can I display the box only ?
    3. When working with 16-bits, including a class in a segment's declaration is an option. I understand that when using flat model, one segment's declaration must include the class   "code", otherwise, ilink32 will display an error. Here, the class "code" tells Windows   that the program contains a code segment (I found that the class "code" may be included   in data's segment declaration. it must not be included in the code's segment   declaration.) Why "end main" is'nt enough ? (like in 16-bit)
    Regards,
    xyoavx
    0
     
    LVL 11

    Expert Comment

    by:dimitry
    1) For this specific issue it is mostly to try, to read online utility help and compiler help
    2) You are doing console application. For it you can do the next trick:
         Create a link to your EXE and change links property to run it minimized. You will have DOS window minimized... Esle you need to create real Win32 GUI application.
    3) I do not know the exact answer for this issue, sorry.
    0
     
    LVL 9

    Expert Comment

    by:BeyondWu
    Here are my answers for your questions:
    1. something comes from experiences, something comes from books, but for all small code snippets and interesting questions I'd like to try it directly! For those very complex questions which impossible to test, I just give the comments and advices.
    2. I don't know why you got a console application, there are must be a parameter for the linker to specify the subsystem type, have you put /Tpe parameter into your linker's command line? There is a /SUBSYSTEM parameter for Microsoft's linker but I can't find anything corresponding parameter for the tlink32...
    If you also can't find it in your machine, you can modify your exe file by hand!  To get a pure GUI application you just need to modify two bytes which locates in the PE header, open your exe file with any hex editor, then find the "PE" at the beginning of the file head, then add 92 bytes offset from the "PE", at that offset I can sure you will find "03 00" in this case, just change it to "02 00", this word means subsystem, 03 means console application, 02 means GUI application....
    3. Don't know the exact answer, first you need to know it quite different between 16bits(MZ) and 32bits(PE) exe format, so it's also quite different between the 16bits and 32bits compiler and linker, it's just a principle and convention, I don't think there is any reasonable reason for it. Sorry, if I'm wrong please correct me...

    regards,
    Wu
    0
     
    LVL 9

    Expert Comment

    by:BeyondWu
    0
     
    LVL 22

    Assisted Solution

    by:grg99
    The "CODE" in quotes is not a segment name, but a "combine type".   The linker groups all segments of the same combine type together, no matter what theyir names.

    0
     

    Author Comment

    by:xyoavx
    Hi grg99,
    Are you sure ?
    As I know, a combine type is: public, common etc. It isn't written between quotes.
    Only a class is written between quotes.
    Regards,
    xyoavx
    0
     
    LVL 22

    Expert Comment

    by:grg99
    You're right!  I meant "class".  

    Same comments apply though.  If you don't get the right segments combining, you're likely to get major linking problems.

    0
     
    LVL 61

    Expert Comment

    by:mbizup
    No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

    I will leave the following recommendation for this question in the Cleanup topic area:
        Accept: BeyondWu {http:#12393736} & dimitry {http:#12406553} & grg99 {http:#12472648}

    Any objections should be posted here in the next 4 days. After that time, the question will be closed.

    mbizup
    EE Cleanup Volunteer
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
    Know what services you can and cannot, should and should not combine on your server.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now