Jose_Gutierrez
asked on
Linking .obj Code
How do you link multiple .obj files to form a single .exe file? (I'm using Borland C++ 5.01)
TLINK file1.obj,file2.obj,file3. obj,output .exe
TLINK file1.obj,file2.obj,file3. obj,output .exe
What's wrong with this answer?
What's wrong with this answer?
ASKER
A proposed answer was:
tlink driver.obj, output.obj, incr.obj, output.exe
But I get the following error:
Fatal: Invalid map filename: incr.obj
The source modules I am trying to link are very simple, as you
can see:
// driver.cpp ////////////////////////// ////////// ////////// ///
int x = 5;
// Function Prototypes
extern void output( void );
extern void incr( void );
void main( void )
{
output();
incr();
output();
}
// output.cpp ////////////////////////// ////////// ////////// ///
#include <stdio.h>
// External Variable Declarations
extern int x;
void output( void )
{
printf( "The value of x is %d.\n", x );
}
// incr.cpp ////////////////////////// ////////// ////////// /////
extern int x;
void incr( void )
{
x++;
}
I compiled these programs seperately, now how can I link them into a single executable?
tlink driver.obj, output.obj, incr.obj, output.exe
But I get the following error:
Fatal: Invalid map filename: incr.obj
The source modules I am trying to link are very simple, as you
can see:
// driver.cpp //////////////////////////
int x = 5;
// Function Prototypes
extern void output( void );
extern void incr( void );
void main( void )
{
output();
incr();
output();
}
// output.cpp //////////////////////////
#include <stdio.h>
// External Variable Declarations
extern int x;
void output( void )
{
printf( "The value of x is %d.\n", x );
}
// incr.cpp //////////////////////////
extern int x;
void incr( void )
{
x++;
}
I compiled these programs seperately, now how can I link them into a single executable?
Sorry, my mistake:
TLINK file1.obj+file2.obj+file3. obj,output .exe
You don't need to specify the mapfile
TLINK file1.obj+file2.obj+file3.
You don't need to specify the mapfile
ASKER
Using the method you suggested, I got the following error:
Fatal: 32-bit record encountered in module DRIVER.C
Then I tried the same method but with Tlink32 and got:
Error: Unresolved external '_printf' referenced from module output.c
Warning: No program entry point
What could be wrong?
Fatal: 32-bit record encountered in module DRIVER.C
Then I tried the same method but with Tlink32 and got:
Error: Unresolved external '_printf' referenced from module output.c
Warning: No program entry point
What could be wrong?
You have to link against the startup module (C0?.OBJ)
and against the standard library.
Alas, last time I did that was like 5 years ago,
so I don't remember exact file names or their locations.
and against the standard library.
Alas, last time I did that was like 5 years ago,
so I don't remember exact file names or their locations.
You didn't way you were trying to link with TILNK32, but the syntax is the same.
>Then I tried the same method but with Tlink32 and got:
>Error: Unresolved external '_printf' referenced from module output.c
>Warning: No program entry point
TO solve this you have to link the C run time library with the rest of your program, but that's not what you asked how to do.
>Then I tried the same method but with Tlink32 and got:
>Error: Unresolved external '_printf' referenced from module output.c
>Warning: No program entry point
TO solve this you have to link the C run time library with the rest of your program, but that's not what you asked how to do.
ASKER
How do you link the C Runtime Library?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.