LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to attach new C header files and libraries in Linux (https://www.linuxquestions.org/questions/programming-9/how-to-attach-new-c-header-files-and-libraries-in-linux-794449/)

zeezulander 03-10-2010 09:33 AM

How to attach new C header files and libraries in Linux
 
Hi,

I have been a predominant Windows user for a long time but shifted to Ubuntu recently. I was just trying out a few basic C functions when i realized that the "conio.h" header file isn't included in the libraries and therefore i was unable to use the "clrscr()" function.

I downloaded a tarball which contained the necessary library and header files including conio.h. Once extracted, i specified the location and included in the program as " #include "path to the header file" ".

I still didn't call the "clrscr()" function, and it compiled successfully. Next i edited the program to call that function and it gave the following error...

" zeezulander@ZeeZuLander:~$ gcc helloWorld.c

/tmp/ccshJs6b.o: In function `main':
helloWorld.c:(.text+0xa): undefined reference to `clrscr'
collect2: ld returned 1 exit status
"

Could someone point out where I've made the mistake and how it could be rectified? and if possible an explanation as to how i can add new libraries in the future?

jamescondron 03-10-2010 09:39 AM

Its not a Linux header, its Windows specific.

Google is your friend: http://www.daniweb.com/forums/thread17584.html

Tinkster 03-10-2010 11:12 AM

No need to send him off to daniweb ...

http://www.linuxquestions.org/questi...ghlight=clrscr

Tinkster 03-10-2010 11:15 AM

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.

Xyro 03-10-2010 12:27 PM

The linker cannot find the library you downloaded.

Code:

gcc ... -L</path/to/lib/dir> -l<libname> ...
is what you're looking for. If the library was placed in the proper location, you wont even need the
Code:

-L</path/to/lib/dir>
part.

paulsm4 03-10-2010 05:23 PM

zeezulander -

Did you get the answer you were looking for?

There *is* no "clrscr" function, nor any "conio.h" header ... for the simple reason that they're obsolete artifacts from DOS. Last I looked, they were available in Windows, but purely for legacy reasons: they're certainly *not* part of the Windows API.

I would strongly discourage you from using anything from "conio.h", even if you did find a wrapper. Unless, of course, you're truly programming for DOS ;)

Otherwise, I would encourage you to explore ncurses (for Linux text-mode), or something like Qt, GTK+ or SDL (for Linux GUIs).

IMHO .. PSM

smeezekitty 03-10-2010 06:26 PM

You could write a wrapper that calls ncurses to clear the screen.

zeezulander 03-10-2010 08:33 PM

What is the correct directory?
 
Quote:

Originally Posted by Xyro (Post 3893169)
The linker cannot find the library you downloaded.

Code:

gcc ... -L</path/to/lib/dir> -l<libname> ...
is what you're looking for. If the library was placed in the proper location, you wont even need the
Code:

-L</path/to/lib/dir>
part.


Hey,

Thanks for the insight.. but what exactly IS the correct directory in which i should place the libraries?

Tinkster 03-10-2010 09:16 PM

Where ever you put the conio library - we wouldn't know.

crts 03-10-2010 09:27 PM

Quote:

Originally Posted by zeezulander (Post 3893650)
Hey,

Thanks for the insight.. but what exactly IS the correct directory in which i should place the libraries?

Libraries usually reside in /lib in Linux.

zeezulander 03-10-2010 10:49 PM

Quote:

Originally Posted by Tinkster (Post 3893676)
Where ever you put the conio library - we wouldn't know.

hi again..

i know where i put the conio library but someone else in the forum stated that there is a standard location in which library files are usually stored.. i want to know what that library file is..

i know the following might sound a little naive.. but the thing is, the tarball i downloaded contained SO many files and conio.h was one file among them.. what exactly do i consider to be the library file? is there some process where i'm expected to concatenate all these files into forming one "library" file? or can the conio.h file be directly used?

I would also like some direction as to where i could find a comprehensive tutorial of the very basics of linux as i feel that all these problems are a result me not understanding how linux works..

If i'm not crossing the line here.. how did YOU guys get acquainted with Linux?

jschiwal 03-10-2010 11:02 PM

The conio.h is a header file. It will be associated with a c library file which you don't want to use.

You need to rewrite your sample code or use a different book. There are plenty gcc C programming books. I'd recommend "Linux Programming by Example" published by Prentice Hall.

zeezulander 03-10-2010 11:02 PM

Quote:

Originally Posted by zeezulander (Post 3893650)
Hey,

Thanks for the insight.. but what exactly IS the correct directory in which i should place the libraries?

Hi,

When i tried the code that you gave me, this is the error pops up...


zeezulander@ZeeZuLander:~$ gcc -L /home/zeezulander/conio -l conio.h

/usr/bin/ld: cannot find -lconio.h

paulsm4 03-10-2010 11:54 PM

Hi, again zeezulander -

I really hate to see you spin your wheels, and I'm very much afraid that might be what's happening.

Q: what is it you're trying to do?

Q: If you're just experimenting with some sample code that happened to use "conio.h", could you please tell us a little bit more about it. For example, where did you get it? Or what is it about the code that interested you?

'Cos here's the deal: "conio.h" is a relic of DOS; a throwback to the late 1980's. If, for whatever reason, the program that uses it is useful to you - cool. We can give you a workaround. But if it's just some "sample code" you wanted to experiment with - heck, we can probably point you in a MUCH better direction.

Either way, please give us a bit more context about what you actually need - and we'd be happy to help.

Anytime!

Sincerely .. PSM

smeezekitty 03-11-2010 12:23 AM

You have to write a wrapper!
Code:

void clrscr(){
    ncurses_clear();
}

should work.
In short, windows libraries dont work on linux. Write your own.


All times are GMT -5. The time now is 01:27 PM.