News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

using ld linker under windows

Started by Emil_halim, October 20, 2010, 09:25:55 PM

Previous topic - Next topic

Emil_halim

Hi all

I am still learning hla with HIDE under windows , i came from mingw c++ , made a graphic  library that rely on some .a libs .
so that i want to use hla with ld linker under windows inside HIDE .

but there is no option  in HIDE for made that job.

any help please?

Sevag.K


sorry, HIDE is hardcoded to use pelle's polink.  i have no plans at this time to support other linkers.
if you can coax mingw to build a coff object or lib of your graphic library, you'll be able to import it in with HIDE.

if not, you'll have to use HLA on the command line or with a more customizable ide.  even then, i don't know if the windows version of hla allows for linking with .a objects.  can ld combine .a and coff objects together?

Emil_halim

oK Sevag.K

no problem, i can make  a bat file that compile hla and link with ld linker. but how can i for HIDE to use that bat for compiling each unit of our project and job?

btw: your HIDE is so easy and i liked it very much.

i want recoding my graphics library with hla and mingw c++ , here is the link of my library link http://www.ogre3d.org/forums/viewtopic.php?f=11&t=25924

thanks

Emil

Sevag.K

thanks!

you have two options.

the manual way is to use the menu Tools-> Run Program
this will open a dialog that gives you a command line for launching programs/batch files.
but you have to do it all the time.


if you want to automate it, you can use a kMake script job.
go to menu Project -> Jobs Manager
for every job you want to build using your script instead of default HIDE settings, click on the job and click on the "Hold" button.  this will remove the job from the build queue.

then create a new Job, for job type, select kMake script and type in a job name, next add a file to this job, only one type is available, give it a script filename (don't type in an extension!  default is .kmk needed for kMake).

you can use this script like a batch file or a make program and don't worry about this warning:

Warning: No [BUILD] entry, starting from top of file

if you want to make the warning go away, simply add [BUILD] at the top of the script.
eg:


[BUILD]
echo this is a kMake script
hla -c -v src\myprogram.hla
ld ...whatever ld arguments are


the advantage of using a kMake script instead of a batch file is that all the HIDE environment shortcuts are available for use.  to find out all the HIDE environment shortcuts, see menu Help -> Show Environment.

i'm still not confident this will work since windows hla only produces coff files, but let me know how it turns out :)

also if you're interested, kMake has some internal commands and file date comparing abilities.  you can check out the manual in Help->HIDE Tools and go to the chapter on kMake.


by the way, that library looks great.

Emil_halim

Sevag.K ,that's so great , and thanks for the full details explanation.

I am away now, when back home i will give a try for the second solution.

about creating coff obj file and linking with ld , i have tried it meany times ago and
it is okay ,so do not wary about that.

yesterday i read  the help of kmake program , it is so powerful but is there a way to
allow kmake to automatically read the hpr file and extract all the unites then compiles
each one?

I am using HIDE 1.5 , the procedure,macro,... window did not display any thing at all , is that
a bug in HIDE?


Sevag.K

Quote from: Emil_halim on October 22, 2010, 11:48:21 AM
Sevag.K ,that's so great , and thanks for the full details explanation.

I am away now, when back home i will give a try for the second solution.

about creating coff obj file and linking with ld , i have tried it meany times ago and
it is okay ,so do not wary about that.

yesterday i read  the help of kmake program , it is so powerful but is there a way to
allow kmake to automatically read the hpr file and extract all the unites then compiles
each one?

unfortunately no, kMake doesn't have that ability.  but there is another way you can do this.
forget what i said about holding jobs in the previous post, keep the jobs in the queue, but instead
of doing a full build, use only the Make-> Build to object files
and make sure your linking script is the last job on the list.  this will make HIDE build the objects normally, but it won't link them.  lastly, it will run your script and all you have to worry about in your script is the linking portion.

unfortunately, HIDE doesn't have a keyboard shortcut for the Build to object files menu.  if this will be inconvenient, i can release a quick upgrade with a keyboard shortcut for it in the next couple days, make it shift-alt-f5

Quote
I am using HIDE 1.5 , the procedure,macro,... window did not display any thing at all , is that
a bug in HIDE?

could be.  first, make sure you have the properties scanning option selected.
Options->General...
in the dialog, the "Scan files for HLA related properties" option should be selected.

if it is selected and you don't see any properties, then it's a bug.

my scanning algorithm is not perfect, sometimes it misses things and if you find anything it misses, let me know and i'll try to fix it.

Emil_halim

Hi Sevag.K

after selecting "Scan files for HLA related properties" option , every thing works correctly.

I am using the folowing scripts for creating DirectXVertices example , only one file to build.


; Kmake script file by Emil_halim
;        using Fasm & ld
;

[MACROS]
filename=DirectXVertices
stack=4194304
temp=units
prgType=windows  ;console
entry=_HLAMain
LIBS = -lHLALIB -lkernel32 -luser32 -lD3D9

[BUILD]
echo this is a kMake script to link with ld , By Emil_halim

   @%p\DirectX\$(temp)\$(filename).obj  %p\DirectX\src\$(filename).hla
   hlaparse  -win32 -@ -level=high -sf -p%p\DirectX\$(temp) %p\DirectX\src\$(filename).hla
   fasm %p\DirectX\$(temp)\$(filename).asm

ld %p\DirectX\$(temp)\$(filename).obj  -o $(filename).exe -s -S -stack $(stack) -entry $(entry) -subsystem $(prgType) -L %h\lib $(LIBS)
upx -9 $(filename).exe
#CLEAN


[CLEAN]
del  %p\DirectX\$(temp)\$(filename).obj
del  %p\DirectX\$(temp)\$(filename).asm


but how can i modify it for multi file project ?

and how to make it a template for my coming projects ?

BTW i am using Fasm for hla backend , and upx for exe compressing task. 

Sevag.K

if you use a foreach loop, all you would have to do is write the 1 list macro with all the files names.

eg:



[MACROS]
;this is a list macro, add more files below as needed
fileNames = "file01","file02","file03"

[BUILD]

<< foreach: fileNames >>
#buildit
<< endfor >>

[buildit]
echo building $(%)
; do your building here, but use $(%) where you normally use the $(fileNames) macro.
; eg:
@%p\Directx\$(temp)\$(%).obj %p\DirectX\src\$(%).hla
;... and so on


the special macro $(%) substitutes all the items in the list macro one by one while the foreach loop is running.

you can also customize this further by using multiple list macros and a foreach loop  for different projects and if you use the right macros you would only need 1 buildit section.


=technically, you don't need to call a builtit section, you can do the entire thing in the foreach loop.  i just did it this way to make it easier to read.

Emil_halim

got the next error

Script Error at line:37
          missing closing parenthesis

here is the script


; Kmake script file by Emil_halim
;        using Fasm & ld
;

[MACROS]
filename="DirectXVertices"
stack=4194304
temp=units
prgType=windows  ;console
entry=_HLAMain
LIBS = -lHLALIB -lkernel32 -luser32 -lD3D9

[BUILD]
echo this is a kMake script to link with ld , By Emil_halim
<< foreach: filename >>
#compile
<< endfor >>

#link
#CLEAN

[compile]
@%c\$(temp)\$(%).obj  %c\src\$(%).hla
hlaparse  -win32 -@ -level=high -sf -p%c\$(temp) %c\src\$(%).hla
fasm %c\$(temp)\$(%).asm


[link]
ld %c\$(temp)\$(%).obj  -o $(%).exe -s -S -stack $(stack) -entry $(entry) -subsystem $(prgType) -L %h\lib $(LIBS)
upx -9 $(filename).exe


[CLEAN]
del  %c\$(temp)\$(%).obj
del  %c\$(temp)\$(%).asm



any help please

Sevag.K

the $(%) macro only works while you are still within a foreach loop!

move the #link and #CLEAN into the foreach loop


<< foreach: filename >>
     #compile
     #link
     #CLEAN
<< endfor >>



edit: and make sure your upx line also uses the list macro:
upx -9 $(%).exe

if you don't do this, you'll need another foreach loop in the CLEAN and link sections.

note: if you're going to delete the *.obj files every time, it's pointless to compare the object files with source filetimes since it will have to build every time!

one further thing, there is a problem with your link line.  i don't know how you would easily resolve this since the link would only be able to link one object file to one executable.  you could not link multiple object files to one executable with this method.

Sevag.K


once you get this script working and have placed it in a job, you can make a template out of it by going to "Project->Create Template"

then, every new project you can use that template and it will automatically make the project with the script job already made.


Emil_halim

still has the same error after making another foreach loop that
enclosed the [link] and [clean] tasks.

i am using only one file for testing purpose , but later i will add
more files to the job.

also the link proses  has to be done only on time and after compiling
all files of job , so how to make it ?

Sevag.K

Quote from: Emil_halim on October 29, 2010, 05:38:47 AM
still has the same error after making another foreach loop that
enclosed the [link] and [clean] tasks.

edit: this was a bug in HIDE, new update is uploaded.  download the 1.50.01 update

https://sites.google.com/site/highlevelassembly/downloads/hide


Quote
i am using only one file for testing purpose , but later i will add
more files to the job.

also the link proses  has to be done only on time and after compiling
all files of job , so how to make it ?

that is a problem, but you may be able to get around it by making a new macro that concatenates all the object file names together and passes it to ld.

but there is a limit to how long a command line can be in windows so this probably won't work with a lot of object files.  kMake can also create temporary files.  can ld accept a file with a list of object files to link in it?

Emil_halim

Nice work Sevag.K

works correctly.

here is the final script source code


; Kmake script file by Emil_halim
;        using Fasm & ld
;

[MACROS]
Mainfilename=DirectXVertices
Unitfilename="Matrix","vector"
LIBS = -lHLALIB -lkernel32 -luser32 -lD3D9

stack=4194304
temp=units
prgType=windows  ;console
entry=_HLAMain


[BUILD]
echo this is a kMake script to link with ld , By Emil_halim
@%c\$(temp)\$(Mainfilename).obj  %c\src\$(Mainfilename).hla
hlaparse  -win32 -@ -level=high -sf -p%c\$(temp) %c\src\$(Mainfilename).hla
fasm %c\$(temp)\$(Mainfilename).asm
<< foreach: Unitfilename >>
#compile
<< macro: units_Obj += %c\$(temp)\$(%).obj >>
<< endfor >>

#link
;#CLEAN
;#CLEAN_UNITS

[compile]
@%c\$(temp)\$(%).obj  %c\src\$(%).hla
hlaparse  -win32 -@ -level=high -sf -p%c\$(temp) %c\src\$(%).hla
fasm %c\$(temp)\$(%).asm


[link]
ld %c\$(temp)\$(Mainfilename).obj $(units_Obj) -o $(Mainfilename).exe -s -S -stack $(stack) -entry $(entry) -subsystem $(prgType) -L %h\lib $(LIBS)
upx -9 $(Mainfilename).exe

[CLEAN]
del  %c\$(temp)\$(Mainfilename).obj
del  %c\$(temp)\$(Mainfilename).asm

[CLEAN_UNITS]
del  %c\$(temp)\$(%).obj
del  %c\$(temp)\$(%).asm



the last problem is , when creating a template code that contained a script make file, you know the script code already has a macro.
this macro replaced by it's value when hied creating the new project , that is wrong , the macro in the script should not chenged
when creating a new project.


Edited:

this will work okay with single file project and multi files project

just comment the unitfilename line for single file project

;**********************************
; Kmake script file  by Emil_halim
;  using Fasm backend & ld Linker
;**********************************

[MACROS]
Mainfilename=DirectXVertices
Unitfilename=Matrix,vector  ; comment this line if no units
LIBS = -lHLALIB -lkernel32 -luser32 -lD3D9

stack=4194304
temp=units
prgType=windows  ;console
entry=_HLAMain


[BUILD]
echo  Kmake script file  by Emil_halim

@%c\$(temp)\$(Mainfilename).obj  %c\src\$(Mainfilename).hla
hlaparse  -win32 -@ -level=high -sf -p%c\$(temp) %c\src\$(Mainfilename).hla
fasm %c\$(temp)\$(Mainfilename).asm
<< if Unitfilename  >>
<< foreach: Unitfilename >>
#compile
<< macro: units_Obj += %c\$(temp)\$(%).obj >>
<< endfor >>
<< endif >>

#link
;#CLEAN
;#CLEAN_UNITS

[compile]
@%c\$(temp)\$(%).obj  %c\src\$(%).hla
hlaparse  -win32 -@ -level=high -sf -p%c\$(temp) %c\src\$(%).hla
fasm %c\$(temp)\$(%).asm


[link]
<< if Unitfilename  >>
ld %c\$(temp)\$(Mainfilename).obj $(units_Obj) -o $(Mainfilename).exe -s -S -stack $(stack) -entry $(entry) -subsystem $(prgType) -L %h\lib $(LIBS)
<< else >>
ld %c\$(temp)\$(Mainfilename).obj -o $(Mainfilename).exe -s -S -stack $(stack) -entry $(entry) -subsystem $(prgType) -L %h\lib $(LIBS)
<< endif >>
upx -9 $(Mainfilename).exe

[CLEAN]
del  %c\$(temp)\$(Mainfilename).obj
del  %c\$(temp)\$(Mainfilename).asm

[CLEAN_UNITS]
del  %c\$(temp)\$(%).obj
del  %c\$(temp)\$(%).asm




Sevag.K

#14
Quote from: Emil_halim on October 29, 2010, 08:58:46 AM
the last problem is , when creating a template code that contained a script make file, you know the script code already has a macro.
this macro replaced by it's value when hied creating the new project , that is wrong , the macro in the script should not chenged
when creating a new project.

you're right.  this is a new way of using HIDE so i haven't anticipated all the problems :)

i'll look into it today.