How to use BC's .lib in TC

How to use BC's .lib in TC

Post by sky » Mon, 11 Dec 2006 02:42:30


Hi all!

I have a device development library(dev.lib), it can be used successfully
under Borland C++ 3.1 but failed under Turbo C 2.01
TC Error message: "Linker Error: Undefined symbol '_functionname' in module
myfile.c"
So I want to know Is there some library can compatible with BC and TC?
if not, how to convert this library to TC format.

Many thanks in advance.

sky
 
 
 

How to use BC's .lib in TC

Post by Ed Mulro » Mon, 11 Dec 2006 04:19:17

The error does not indicate the library is not compatible. It indicates
that the function called from the code in myfile.c was not found in the
library.

Run tdump.exe on the object file and on the library to see what is in each.

You might do it this way:

tdump myfile.obj | grep -i functionname
tdump libname.lib | grep -i functionname

Now compare the exact text of the function names including case.

My guess is that the function is PASCAL in the library and the default C
calling conventions in myfile.c so that the names are like this:

functionname in myfile.c source code
_functionname in myfile.obj
FUNCTIONNAME in libname.lib

Or it could be that the library name was not given to TC 2.01 when doing the
build.

. Ed

 
 
 

How to use BC's .lib in TC

Post by sky » Tue, 12 Dec 2006 01:16:20

Thank you Ed

I have read the function information by tdump.exe, there is a Underscore
character(_) is prefixed to function name in the .obj file.
set the option 'Generate underbar' OFF in TC 2.01
I can get the same function name in .lib and .obj, but linker errors still
exist.

The library file has been added to the file list in the prj file.

The attachment is the test project including the target library(in
attachment group, topic: Library in TC project).

Any hint?

TIA

sky
 
 
 

How to use BC's .lib in TC

Post by Ed Mulro » Tue, 12 Dec 2006 02:02:31

The file posted in the attachments group is a *.rar file. It is not a lib
format file and there is no added value to a project file as you have
already told me that the library name is in the project. That mostly
insures that the project is correct unless you forgot to include the .LIB
extension in the name.

DO NOT enable the option to turn the leading underscore off. That is for
specialized uses and not for this situation.

A function declared in the default of C calling conventions has its public
name formed the same as in the source code but with an added leading
underscore.

16 bit programs also use the pascal calling convention (normally by using
the macro PASCAL). For that the public function name is the same as in the
source code but with all letters forced to upper case (all capital letters).

Calling conventions are not just how a public name is formed. They also
specify in what order calling the values of arguments are given to functions
and how the stack is handled when the function returns.

Forcing compatibility by suppressing leading underscores in a DOS program is
playing with fire.

TC 2.01 is from 1986 except for minor tweaks added in '89. BC++ 3.1 is from
1992 and, along with other enhancements, added C++ so needed to alter the
debug information records.

Maybe it is the debug information that is confusing TC 2.01.
Try this:

-Save a copy of the original library somewhere else, perhaps in
another directory.
-Give this command to get a list of all the object files in the library
tlib /C libname.lib , libname.lst
- Make up a text file something like this listing the object files
*file1.obj &
*file2.obj &
*file3.obj &
*file4.obj
(note that the last line does not have an ampersand (a '&') and that
there is a space before each ampersand)

- Give this command to get copies of the object files in the library
(I am using resp.txt for the file created above)
tlib /C libname.lib @resp.txt

- Give this command to strip the debug info from the files
for %a in (*.obj) do tdstrip %a
(if you use a batch file then use %%a instead of %a)

- Give this command to substitute these new object files for the
original ones in the library
for %a in (*.obj) do tlib /C libname.lib -+%a
(if you use a batch file then use %%a instead of %a)

Now try the build again using this new version of the library.

Note that when you finally do complete the build you must also consider what
memory model the library was built for and make your source code be built
with that same memory model.

. Ed
 
 
 

How to use BC's .lib in TC

Post by sky » Wed, 13 Dec 2006 01:28:57

nce again, thanks.

the *.rar file is a compressed file that include all the project files, I
have post another copy with *.zip format to the attachments group.

the following is the result by tdump.exe
obj:
File STDIN:
0000E0 EXTDEF 1 : '_ibdev' Type: 0

lib:
File STDIN:
Public Symbol Type: 3A Function Return Offset: 02 bytes003EAC PUBDEF
'ibdev(int, int, int, int, int, int)' Segment: _TEXT:0923

I'll try to alter the debug information records according to your method.

BYW, The library file was built with Turbo C++ 3.00(I checked the library
file with binary editor)

I'm a beginner in DOS programme.

sky


----- Original Message -----
From: "Ed Mulroy" < XXXX@XXXXX.COM >
Newsgroups: borland.public.cpp.borlandcpp
Sent: Monday, December 11, 2006 1:02 AM
Subject: Re: How to use BC's .lib in TC




 
 
 

How to use BC's .lib in TC

Post by sky » Wed, 13 Dec 2006 01:29:54

don't find any object files in the library when I give the command: tlib
/C dosgpib.lib , dosgpib.lst
only get a list of the public symbols in the library, any hint?



 
 
 

How to use BC's .lib in TC

Post by Bob Gonde » Wed, 13 Dec 2006 01:38:32


The lib appears to contain C++ functions compiled with
TC86 Borland Turbo C++ 3.00

The header file shows
extern int ibwrt(int ud, char *buf, long cnt);

But a hex editor looking at the lib shows
@ibwrt$qipzcl
 
 
 

How to use BC's .lib in TC

Post by Ed Mulro » Wed, 13 Dec 2006 05:05:52

> Public Symbol Type: 3A Function Return Offset: 02 bytes003EAC PUBDEF

That is a C++ function. You are trying to call it from C. The public names
of C++ functions are not formed in the same manner as C functions. Turbo C
2.01 does C, not C++. You cannot call that function from Turbo C 2.01.

. Ed
 
 
 

How to use BC's .lib in TC

Post by Kevin G. R » Wed, 13 Dec 2006 08:25:59

> You cannot call that function from Turbo C 2.01.

TC 3.0 has been available on eBay and as part of the original Turbo Suite
package. BC 3.0, 3.1, 4.0, 4.5x and 5.0x are available on eBay.

You would be wise to get a more recent compiler than TC 2.0 for
what you are trying to do.

Sincerely
Kevin
 
 
 

How to use BC's .lib in TC

Post by sky » Thu, 14 Dec 2006 00:37:00

many thanks!

The C++ function in binary library cann't be invoke in C function, right?

What's the difference between C function and C++ function?

but how to use the library that contain C++ functions in TC environment?
or how to convert the TC project to BC++ project.

I have created a BC project and add all the files in original TC project
into the new BC project, compile successully but link failed.
Error information: Linkder Error: Segment -TEXT exceeds 64K

any hint?

sky
 
 
 

How to use BC's .lib in TC

Post by Ed Mulro » Thu, 14 Dec 2006 04:00:58

C calling convention functions have public names the same as the source code
except for an added leading underscore.

C++ functions have public names with a different leading character and with
the list of calling argument types encoded into characters added to the end
of the name.

For example
int FuncName(int i);
C public name: _FuncName
C++ public name: @FuncName$qi

If in the C++ source code if the function does not take or return anything
that is specific to C++ then the C++ source code can be arranged to make it
callable from C by decorating the C++ function with
extern "C"
so that its public name is as would be created by a C program.


In 16 bit programs memory is organized into segments of up to 64K. Memory
models are used to specify how a program might arrange and use these
segments. Depending upon the settings, all source files share the same code
segment or each source file has its own code segments.

The default Small model uses only one segment for the code and that segment
has the name 'TEXT'. If your program has but one source file then break it
up into more than one. Change your memory model to Medium or Large. Then
do a Project|Build_All.

. Ed
 
 
 

How to use BC's .lib in TC

Post by sky » Thu, 14 Dec 2006 19:47:55

The project can be compiled and linked after changing memory model under
Borland C++ 3.00

Input the C++ function library and invoke the C++ function of it in my
source code, compile: passed, link: symbol not found.

check .obj file by tdump.exe, it's a C function yet.

How can I convert the C project to C++ project? change the project options
or modify my source code?

What is the entitative difference between C project and C++ project? Both
can be compiled and link in C++ environment?

Thank you

sky



"Ed Mulroy" < XXXX@XXXXX.COM > :457efc2d$ XXXX@XXXXX.COM ...
 
 
 

How to use BC's .lib in TC

Post by Ed Mulro » Fri, 15 Dec 2006 02:00:08

orry but BC++ 3.0 is from 14 years ago and I don't remember it well enough
to give you step by step guidance through the project options. You'll have
to look around to see where and if it has a C project selection.

Why you need a C instead of C++ project is also a question. All files with
the extension of .C are already taken as C language. Files with the
extension of .CPP are taken as C++.

If the header file has C functions in it then you can do this in the header
file to make sure that a C++ source file will properly recognize its
contents as C language.

----start of header file----
#ifdef __cplusplus
extern "C" {
#endif
----current contents of header file----
#ifndef __cplusplus
}
#endif
----end of header file----

The macro __cplusplus used above is required by the language specifications
to be defined in C++ programs. The #ifdef tests if the source file is being
compiled as C++.

. Ed

"sky" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...