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
Solved

Linking .obj Code

Posted on 1998-01-03
9
492 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 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