?
Solved

Linking .obj Code

Posted on 1998-01-03
9
Medium Priority
?
495 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 280 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

762 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