• C

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

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.

Who is Participating?
nils pipenbrinckCommented:
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

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)
virgo21Author Commented:
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. :)

The Firewall Audit Checklist

Preparing for a firewall audit today is almost impossible.
AlgoSec, together with some of the largest global organizations and auditors, has created a checklist to follow when preparing for your firewall audit. Simplify risk mitigation while staying compliant all of the time!

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.
virgo21Author Commented:
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.
virgo21Author Commented:
Increased points.
wcl myconio.c mytest.lib
This is the shortest way  to do it.
virgo21Author Commented:
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.
virgo21Author Commented:
Trying to reject answer since it dosen't work.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.