News:

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

using GOLINK on all *.obj file in a folder

Started by dszafranski, August 17, 2010, 12:22:26 AM

Previous topic - Next topic

dszafranski

Hi,

I have over 150 individual .obj files created by goasm that I'd like to link into my projects. Can I
specify all of the *.obj files in a folder?

golink myapp.obj myapp.res \lib\*.obj

One more question, will the linker only add/link the required obj files required by myapp (functions/data/vars)
or will it link all of them to myapp.exe?

If specifying all obj files in folder ( \lib*.obj) is not possible, then what other way is there to do this without trying
to specify 150 obj files on the golink command line.

thanks

donkey

It sounds more like you would want to make a LIB file than a whole series of object files. The Microsoft LIB.EXE program will assemble a lib file that you can use with GoAsm and it will meet your requirements. Once assembled you have only to specify the file where the function resides and only those functions that are necessary will be linked into your application. In order to build your lib file you can do this:

(assuming that the OBJ files were built from multiple GoAsm ASM files)

GoAsm.EXE /c /ms *.asm

LIB.EXE /OUT:mylibrary.lib *.obj

When you use them in your program:

invoke mylibrary.lib:SomeFunction, param1, param2

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dszafranski

Quote from: donkey on August 17, 2010, 12:35:15 AM
It sounds more like you would want to make a LIB file than a whole series of object files. The Microsoft LIB.EXE program will assemble a lib file that you can use with GoAsm and it will meet your requirements.

Thanks Edgar. That is exactly what I am currently doing.

I was hoping I could use golink as my linker instead of ms link.exe.

I'm trying to find a way to use my current assortment of assembly libraries. golink doesn't seem to work with
any of my static .lib files.

My goal is to get away from needing system .lib files for kernel32.dll, gdi32.dll, etc and just use statically linked libraries
or their equivalent using golink. But perhaps this is not yet possible.

thanks.


donkey

Hi figeater,

I am not sure that you are using GoAsm then as it does not need any lib files for system libraries at all. GoLink does not link library functions in GoTools programs, that is the job of GoAsm (the assembler) which also does the job of importing any functions from DLLs like kernel32 and user32 etc... As for statically linked versions of system libraries I am not aware of any that exist, at least outside of Microsoft, and even then they would create massive versioning problems to use them.

As a general rule of thumb, all linkers will simply link every object file you pass to it regardless of whether you are using it or not, there are none that I know of that check to see if it has been referenced since it is possible (and even likely in DLLs) that there will be many unreferenced functions that you want included. What you are looking for is a LIB file, you have basically described its function exactly.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dszafranski

Edgar,

Thanks for the reply. I think I need to restate what I wanted to accomplish.

1. I am currently using goasm, and using ms tools like lib and link to create executables and static libraries.

2. If possible, I would like to migrate to using golink and gorc and drop the ms tools.

3. I have many static libraries, each containing hundreds of functions, but I have not found a way to link them using golink.

So is there a way to use golink with static libraries like I currently do using ms link.exe?

thanks

David

donkey

Hi,

Let me restate my point in another way, GoAsm.exe (not GoLink) is the program that imports functions from static libraries. When you call a function in a static library you do as follows:

invoke mystatlib.lib:function, parameter1, parameter2,...

When you use invoke in this way GoAsm will import the function and any dependencies contain in the lib file. Be aware however that GoAsm is not able to import any dependencies across lib files, they must be self contained. I usually define the function in a header then use it normally, for example

#define function mystatlib.lib:function

invoke function, parameter1, parameter2,...


Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

dszafranski

Hi Edgar,

Ok, thanks so much. I finally understand that goasm can call the static library directly! I had no idea this was possible.
And I've read the manual several times and never noticed this ::)

Currently I do this:

call  %_null.d

so now I could do this

call mylib.lib:%_null.d

Ok, now it looks like I may need to combine all of my static libraries into one jumbo one so I don't
need to know exactly which specific static library to call.

Thanks for taking the time to help me.

David


Vortex

Hi figeater,

Here is an example for you.


\goasm\goasm lowercase.asm
\goasm\goasm uppercase.asm
\goasm\goasm StdOut.asm
\goasm\goasm StrLen.asm

\masm32\bin\polib /OUT:testlib.lib *.obj /MACHINE:X86


Polib.exe is Pelles library manager coming with the Masm32 installation. This librarian is a tool of Pelles C development suit.

Using the functions in the static library :


#define uppercase testlib.lib:uppercase
#define lowercase testlib.lib:lowercase
#define StdOut testlib.lib:StdOut

.data

str1    db 'string converted to uppercase.',13,10,0
str2    db 'THIS STRING CONVERTED TO LOWERCASE.',0

.code

start:

    invoke  uppercase,ADDR str1
    invoke  StdOut,eax
    invoke  lowercase,ADDR str2
    invoke  StdOut,eax
    invoke  ExitProcess,0


donkey

There are advantages to having many lib files, editing and debugging is easier when they are split up into smaller related libraries. I would create multiple lib files and a global header file that instructs GoAsm which library contains the function. You can do it like this:

Header file
#define function1 lib1.lib:function1
#define function2 lib1.lib:function2
#define function3 lib2.lib:function3
#define function4 lib2.lib:function4
#define function5 lib2.lib:function5
#define function6 lib3.lib:function6
#define function7 lib4.lib:function7
#define function8 lib4.lib:function8


#include the header file in your program then when you call them you have only to use the function name:

call function4

GoAsm will translate function4 to lib2.lib:function4 and import the function from the correct lib file.

Edgar
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable