Make a small c lib using Watcom C/C++ 10.6.

Posted on 1997-04-18
Last Modified: 2008-03-10
How do I make a small library in c, Using Watcom C/C++ 10.6.
Here are some sample code I have tried.
The code works, just wanna know how to put it in a LIB ?

I compiled the myconio.c to myconio.obj then used the library
utility to make myconio.lib, but then I can't use it.

How should myconio.h look like and how should I go about doing a lib ?

// myconio.h
extern void clrscr(void);

// myconio.c
void clrscr(void);
#pragma aux clrscr =            \
      "Mov Ax, 0B800h"        \
      "Mov Es, Ax"            \
      "Mov Cx, 07D0h"         \
      "Xor Di, Di"            \
      "Mov Ax, 0700h"         \
      "Rep stosw";
// clrscr ends.

Question by:virgo21

Expert Comment

ID: 1249951
You say you can't use it ?

Is it the lib file or the lib creater util you can't use ?

What is the error message/problem ?
(I can't use it does not say much about the problem)

Author Comment

ID: 1249952
What I mean is when I have created the myconio.lib
how do I then use the function in a c program ?
Have I declared the prototype correctly in the header file ?

I do like this.

wcc myconio.c -> myconio.obj
wlib -b -n myconio +myconio -> myconio.lib

Now I'll create a file called mytest.c:
// mytest.c

then I do wcl mytest.c ->

D:\DEV\WATCOM\BINW>wcl mytest.c
WATCOM C/C++16 Compile and Link Utility Version 10.6
Copyright by WATCOM International Corp. 1988, 1996. All rights reserved.
WATCOM is a trademark of WATCOM International Corp.
       wcc MYTEST.C
WATCOM C16 Optimizing Compiler  Version 10.6
Copyright by WATCOM International Corp. 1984, 1996. All rights reserved.
WATCOM is a trademark of WATCOM International Corp.
MYTEST.C: 6 lines, included 15, 0 warnings, 0 errors
Code size: 9

WATCOM Linker Version 10.6
Copyright by WATCOM International Corp. 1985, 1996. All rights reserved.
WATCOM is a trademark of WATCOM International Corp.
loading object files
searching libraries
Warning(1028): clrscr_ is an undefined reference
creating a DOS executable
file MYTEST.obj(D:\DEV\WATCOM\BINW\MYTEST.C): undefined symbol clrscr_
Error: Linker returned a bad status

What am I doing wrong ?
Please help and forgive me for not giving enough info. :)


Expert Comment

ID: 1249953
You need to link your program with your library. I don't use Watcom C but look up your link help and it will tell you the commands. An alternative is to set up a project in the IDE including your program and library.
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Author Comment

ID: 1249954
Watcom dosen't have an IDE it's totally command based, at least the one I'm using. I think it's because I only use the DOS hosted Watcom compiler.

I could always link in the .obj file like something like this:
wcc myconio.c
wcc mytest.c
wlink myconio.c mytest.c

then I would get a .exe file that works, but that was what I wanted to avoid.

I need an answer from somebody who knows about Watcom C/C++.

Thanks for your answer, but your answer should have been a comment since it's not an answer only a suggestion.

I have allready tried to read the online manuals, but they really suck, It's very difficult to find the info you need.
If I could find the answer in the manuals I wouldn't ask around here. :)

Hoping for a really good answer.

Author Comment

ID: 1249955
Increased points.

Expert Comment

ID: 1249956
wcl myconio.c mytest.lib
This is the shortest way  to do it.

Author Comment

ID: 1249957
bjacob: Your answer dosen't work at all.
By the way you got the extensions wrong. :)
Neither of theese works for me though:
wcl myconio.lib mytest.c
wcl mytest.c myconio.lib

Thanks for your try, I really thought this question was simple, but maybe not ?

Have a nice day all of you.

Author Comment

ID: 1249958
Trying to reject answer since it dosen't work.

Accepted Solution

nils pipenbrinck earned 40 total points
ID: 1249959
I have an answer that'll work!

Please note: If you write #pragma statements to inline assembly-code into your c-files no code will be generated at this point. The code will be directly expanded into the function that actually calls the subroutine.

Therefore your object file didn't contain any single public definition.

Now you have two options to make your library:

1. Put the routine into the headerfile (along with the #pragma).
   Whenever you now use clrscr the compiler will inline the code.
   (nice and fast. Since the function is very tiny I would go    this way.

2. Rename the function to something like clrscr_inline and create
   a function in your c-file which calls clrscr_inline.

   It would look like this:

   void clrscr (void)

   Now you've generated code and the object file will contain
   a public definition for clrscr. The librarian and linker will
   find the function and you'll get rid out of your errors.

I tested it.. It works!


 Nils Pipenbrinck


Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which checksum is this? 7 142
C++ vs C compilers 13 159
distributed computing in Python 4 122
Raspberry Pi 3 to send text message 9 108
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

813 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

14 Experts available now in Live!

Get 1:1 Help Now