Solved

Linking .obj Code

Posted on 1998-01-03
9
493 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
Independent Software Vendors: 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!

 
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

Industry Leaders: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

726 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