Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ilink32 error

Posted on 2004-10-23
11
Medium Priority
?
903 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
Comment
Question by:xyoavx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 9

Accepted Solution

by:
BeyondWu earned 672 total points
ID: 12393736
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
dimitry earned 664 total points
ID: 12406553
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
ID: 12425253
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 11

Expert Comment

by:dimitry
ID: 12425438
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
ID: 12431145
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
ID: 12450355
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 664 total points
ID: 12472648
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
ID: 12474530
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
ID: 12475599
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
ID: 15625737
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

636 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