Solved

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

Posted on 1997-04-18
9
621 Views
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.

0
Comment
Question by:virgo21
9 Comments
 
LVL 2

Expert Comment

by:tovergaard
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)
0
 

Author Comment

by:virgo21
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
main()
{
   clrscr();
}

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

0
 
LVL 2

Expert Comment

by:bjacobs
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.
0
 

Author Comment

by:virgo21
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.
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:virgo21
ID: 1249955
Increased points.
0
 
LVL 2

Expert Comment

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

Author Comment

by:virgo21
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.
0
 

Author Comment

by:virgo21
ID: 1249958
Trying to reject answer since it dosen't work.
0
 
LVL 4

Accepted Solution

by:
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)
   {  
     clrscr_inline();
   }

   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!

Regards,

 Nils Pipenbrinck

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

706 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

20 Experts available now in Live!

Get 1:1 Help Now