Working with Masm from command-line...how do you get .inc to actually link....

Started by chadsxe, March 03, 2007, 12:22:16 AM

Previous topic - Next topic

chadsxe

1) I am working Ml from the command line.
2) I have all my files in one folder.  This includes my source .asm file, all my .inc files, the ml.exe, the link.exe, etc
3) I run ML from my command line like so \ml /c /coff "test.asm"
4) It creates the .obj file
5) I then then run LINK from the command line like so \link /SUBSYSTEM:WINDOWS /OPT:NOREF "test.obj"
6) The linker then tells me that there were a couple of unresolved external symbols that were refrenced.  These functions are parts of the .inc.  So I am guessing that I am not using ML correctly.

Any thoughts

Thanks

Chad

TNick

When you say "all my .inc files" you are saing that you had copy all the include files from include folder?
There is really no need for all this copy!
Here is an example:

Supose you have the masm32 package in the C drive
1) Create a new folder in the root of C drive and name it MyProg
2) Create a new folder within c:\MyProg\ and name it First
3) Create a text file in c:\MyProg\First called First.asm
4) Open this file and enter the following text

.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE windows.inc
INCLUDE kernel32.inc
INCLUDE user32.inc
INCLUDELIB kernel32.lib
INCLUDELIB user32.lib
.DATA
  AppName  BYTE  "First app",0
  Message  BYTE  "Hello, there!!!",0
.CODE
App_Entry_Point:

INVOKE MessageBox,NULL,ADDR Message,ADDR AppName,MB_OK

INVOKE ExitProcess,0
END App_Entry_Point


5) Save this file and create another file in c:\MyProg\First named MakeMe.bat
6) Entre following text in MakeMe.bat
Quotec:\masm32\bin\ml /c /coff /I"C:\masm32\include" "first.asm"
c:\masm32\bin\link /SUBSYSTEM:WINDOWS /RELEASE /VERSION:4.0 /LIBPATH:"C:\masm32\lib" /OUT:"first.exe" first.obj
first.exe
7) save it and double click this file

Now, if you want to add a new file to this project, create the file in c:\MyProg\First directory and add this line just below
INCLUDELIB user32.lib:

INCLUDE MyNewFile.asm ;name and extension of the file that you have created

To add an existing file, if that file is in the same directory (c:\MyProg\First) just INCLUDE his name in the same spot. If is in another directory, use it's full path. For inc files that are stored in C:\masm32\include you don't have to use full path but names. The /I directive tells to ml to look in that path for inc files that he can't find in current path.
Same is true for lib files. If a library file is outside C:\masm32\lib, you need a full path.
Why you need kernel32.inc \ .lib and user32.inc \ lib? The two api functions that were used are stored in
- kernel32.dll - ExitProcess
- user32.dll - MessageBox
When you use any API function, you have to make shure that the linker has access to the lib file that contains informations for finding the right function within the dll. So, when you have an error message that tells you that an unresolved external symbol is there, and the symbol's name is an API name, you forget to add a coresponding .lib file.
Use win32.hlp to locate the function, then use "Quick Info" link to see where that function reside and add the right inc and lib files.

Hope this helps. Feel free to ask any other question or to tell me that you already know all this! :)

Regards,
Nick




MichaelW

To add a little more information, .inc files generally contain function prototypes (declarations), with the actual functions in libraries (either static libraries or DLLs). The INCLUDELIB directive is an easy method of informing the linker that it needs to link with the specified library, so it can resolve any references to the functions in the library.
eschew obfuscation

chadsxe

O.k hear is my issue.....I want to pass this project file off to diffrent workstations and I don't want to have to worry about if that work station has the same directory setup as my orginal workstation.  So....with in my program I am running ml through a system call that passes command line arguments.  I have the ml.exe in my project folder - not the default folder.  I have a .inc and .lib in the same path (project folder) as the ml.exe.  When the program executes it builds a .asm file then effectively runs ml.exe and passes the built .asm file to it.  It then runs the link.exe (which again is in the same directory) and upon excuting it tells me that a few function prototypes were not defined.  These function prototypes are a part of the .inc that I am includeing with my project.  Now I know that the .inc (and the files it calls) is not the issue because "ha" I did not build them and I have them working with some other projects.  I am guessing that when I do execute the ml.exe it is not building my .obj file correctly.  Here is a question......when an .obj file is built does the called .inc files get encompassed in the .obj file?  So....back to my problem.  Is my method not going to work?

hutch--

Chad,

Your questions are prety straight forward PATH issues. If ML and LINK can find the files, even spread over different drives and networks, the result will build but the more complex the collective path structures are, the more difficult it will be to make it work correctly.

You have "include" for text files which means your INCLUDE files, "includelib" for binary libraries and you can also use the SET command from the command line to set environment variables. Note also the path options with LINK.

I personally use the installations LIB and INCLUDE directories for normal stuff but if I am writing a custom library I make a directory off the one I use for the project and put custom libraries in it so the app just needs,


include lib\myfile.inc
includelib lib\myfile.lib
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

chadsxe

WOWOWOWOWOOWOWHAHAHHAHAHahahahH :P :bg :dance: :cheekygreen: :green :toothy

I figured it out...

I can't thank everyone enough.  I learned something from each reply. Honest.

Regards

Chad