Solved

Linking .obj Code

Posted on 1998-01-03
9
486 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now