News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

How to merge two obj file?

Started by Emil_halim, January 02, 2018, 02:28:56 AM

Previous topic - Next topic

Emil_halim

Hi ALL

I am working in integrating uasm and c-- , but each one produces it's obj file , so i want to merge them together in one final obj file.

I know that the linker will do the job when linking , but my problem is like that. consider the following example.

/* NewSphinxC-- & Uasm Example  */

#include <windows.h>   
#include <MSVCRT.H-->

extern cdecl _getch();

int h; 

// start uasm here
.MODEL flat, c     

EXTERNDEF h:SDWORD

.data
  vdword dd 300
  vword  dw 200
  vbyte  db 1 
     
align 4
.data?
  pdword dd ?
   
.code 
kput:
   push [ESP+4] 
   call puts
   add  esp,4
   call  _getch
   ret 4
   
mtest Proc
       mov eax , 100   
   mov pdword,eax
   mov h,eax
       ret
mtest Endp   

End

main()
{
   int k;
   k=mtest();
   kput("press any key...");
   puts("welcome");
   printf("%d\n",vdword);
   printf("%d\n",vword);
   printf("%d\n",vbyte);
   printf("%d\n",pdword);
   printf("%d\n",h);
   ExitProcess(0);
}


this one source code will produces two obj files 'kput.obj' & 'kput_m.obj' , the first one will pass to the linker by the IDE , but the other will not, so i want to merge two obj in
one obj that will pass by IDE.

Vortex

Hi Emil,

Writing a tool combining object modules would be a hard job. In the daily life, merging two object files is not practiced.

fearless

why not just pass *.obj to the linker? or each obj name seperately?

habran

It is not a bad idea Emil :biggrin:
It is possible to do that with UASM with MSVS but you have to use separate source files for .ASM and .C,
VS will take care to link them. To use UASM with VS you have to use UASM targets.
You can debug it as well from VS debugger by just setting breakpoints in sources both asm and c.
It is actually very useful when writing big APPs.
We are planing to write C preprocessor for the C headers so that we can use .h headers directly without converting them to .inc files.
I was looking into c-- if it can serve for that purpose but unfortunately it is able to work only with 32 bit,
maybe one day you decide to extend it to 64 bit, in that case we will negotiate ;)

Anyway, I appreciate your interest in unconventional stuff :t

regards


Cod-Father

hutch--

The simplest way to merge 2 or more object modules is to put them into a library. Then just include the library into the app. Microsoft's LIB.EXE will do that job just fine.

Habran,

That is a really good idea, once you can use the Microsoft header files you are free of all of the conversions.

aw27

Quote
I am working in integrating uasm and c--
Are you using the Quick C-- compiler (no longer maintained) ?

Emil_halim

Thank you ALL.

@  Vortex
I got you , and agree with you.

@ fearless
I was thinking the same as you , but it is a bit dangerous to include all obj file , suppose that you don't want to include a specific obj one.

@ habran   
I already (in my Example) let uasm to use headers from sphinx C-- , so i include this in the start.

#include <windows.h>   
#include <MSVCRT.H-->

Also i am using Pelles IDE, I made a plugin to handle C-- files.
At first i separate this source code into two files but with .c-- extension,  then let C-- detects the '.MODEL' , so that the control pass to Uasm , then when uasm finished the control pass back to c--.
The main reason for not separation is that , how to pass c-- stuff (API declarations) to Uasm , also for the opposite direction passing Uasm stuff to C--, only mixing them in one source code allows us to do that.
The Include Path is determen by C-- , if you have inc files for Uasm , put them with C-- include folder.
The only drawback here is C-- does not understand all C headers.
about the C-- for 64bit , i don know how , remember that i am not the owner of C-- ,so i extended it as i can.
Here is Uasm part.

// start uasm here
.MODEL flat, c     

EXTERNDEF h:SDWORD

.data
  vdword dd 300
  vword  dw 200
  vbyte  db 1 
     
align 4
.data?
  pdword dd ?
   
.code 
kput:
   push [ESP+4] 
   call puts
   add  esp,4
   call  _getch
   ret 4
   
mtest Proc
       mov eax , 100   
   mov pdword,eax
   mov h,eax
       ret
mtest Endp   

End

 
As you see , the functions  puts ,  _getch are not declared in Uasm.

Also in C-- part

main()
{
   int k;
   k=mtest();
   kput("press any key...");
   puts("welcome");
   printf("%d\n",vdword);
   printf("%d\n",vword);
   printf("%d\n",vbyte);
   printf("%d\n",pdword);
   printf("%d\n",h);
   ExitProcess(0);
}

The Variables vdword,vword... and the procedures kput, mtest are not declared in Uasm.

@ hutch--
I tried your idea but it did not work because the PoLinker  did not see the main function when it is in Lib file but it okay with obj file.

@  aw27
It is not Quick C-- , see this http://c--sphinx.narod.ru/indexe.htm



habran

If you want to use uasm and c-- to create a same object you will probably have to tweak a bit c-- to create 1 object or let linker know that there are 2 object to link together.
The first option would be better. Remember, anything is possible if you want it with unbending intent ;)
Cod-Father

Emil_halim


thanks for this idea , it is hard to do it , but i will try.

Emil_halim

Hi All

I tweaked C-- , it was allowing include obj file to merge with final exe file. but it was buggy.

I fix it and now i can import procedures from obj file , but there is no information of data in obj file.

For example , if we have a long type variable in the obj file , how to know it's type from symbol table in obj file?

I think that , all compiler did not include information about data and post data.

any help please.