Solved

Linking .obj Code

Posted on 1998-01-03
9
491 Views
Last Modified: 2012-06-21
How do you link multiple .obj files to form a single .exe file? (I'm using Borland C++ 5.01)
0
Comment
Question by:Jose_Gutierrez
  • 5
  • 3
9 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1177429
TLINK file1.obj,file2.obj,file3.obj,output.exe
0
 
LVL 32

Expert Comment

by:jhance
ID: 1177430
TLINK file1.obj,file2.obj,file3.obj,output.exe

What's wrong with this answer?
0
 

Author Comment

by:Jose_Gutierrez
ID: 1177431
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?
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 32

Expert Comment

by:jhance
ID: 1177432
Sorry, my mistake:

TLINK file1.obj+file2.obj+file3.obj,output.exe

You don't need to specify the mapfile
0
 

Author Comment

by:Jose_Gutierrez
ID: 1177433
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?
0
 
LVL 2

Expert Comment

by:mlev
ID: 1177434
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.
0
 
LVL 32

Expert Comment

by:jhance
ID: 1177435
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.
0
 

Author Comment

by:Jose_Gutierrez
ID: 1177436
How do you link the C Runtime Library?
0
 
LVL 32

Accepted Solution

by:
jhance earned 70 total points
ID: 1177437
BCC should know how to do this itself.  I have only V4.0 of Borland C++ but here is the command line to link a 32-bit Console (i.e. MS-DOS) application:

C:\>BCC32 -IC:\BC4\INCLUDE -LC:\BC4\LIB TEST.CPP

(the C:\BC4 will vary depending on where your Borland C++ is installed.  It may also be different than BC4 depending on what version you have and where you have installed it.)

The output of the above file is TEST.EXE.  If you have more than one source file (like you originally mentioned), you can just specify each of the C++ source files on the same command line like:

C:\>BCC32 -IC:\BC4\INCLUDE -LC:\BC4\LIB TEST1.CPP TEST2.CPP TEST3.CPP
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question