LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2010, 09:33 AM   #1
zeezulander
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Rep: Reputation: 0
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?
 
Old 03-10-2010, 09:39 AM   #2
jamescondron
Member
 
Registered: Jul 2007
Location: Scunthorpe, UK
Distribution: Ubuntu 8.10; Gentoo; Debian Lenny
Posts: 961

Rep: Reputation: 70
Its not a Linux header, its Windows specific.

Google is your friend: http://www.daniweb.com/forums/thread17584.html
 
Old 03-10-2010, 11:12 AM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
No need to send him off to daniweb ...

http://www.linuxquestions.org/questi...ghlight=clrscr
 
Old 03-10-2010, 11:15 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 03-10-2010, 12:27 PM   #5
Xyro
LQ Newbie
 
Registered: Aug 2009
Location: Canada
Distribution: Ubuntu 9.04
Posts: 22

Rep: Reputation: 19
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.

Last edited by Xyro; 03-10-2010 at 12:30 PM. Reason: elipses fail
 
Old 03-10-2010, 05:23 PM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 03-10-2010, 06:26 PM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
You could write a wrapper that calls ncurses to clear the screen.
 
Old 03-10-2010, 08:33 PM   #8
zeezulander
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
What is the correct directory?

Quote:
Originally Posted by Xyro View Post
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?
 
Old 03-10-2010, 09:16 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Where ever you put the conio library - we wouldn't know.
 
Old 03-10-2010, 09:27 PM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by zeezulander View Post
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.
 
Old 03-10-2010, 10:49 PM   #11
zeezulander
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Tinkster View Post
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?
 
Old 03-10-2010, 11:02 PM   #12
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 03-10-2010, 11:02 PM   #13
zeezulander
LQ Newbie
 
Registered: Nov 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by zeezulander View Post
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
 
Old 03-10-2010, 11:54 PM   #14
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 03-11-2010, 12:23 AM   #15
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
You have to write a wrapper!
Code:
void clrscr(){
    ncurses_clear();
}
should work.
In short, windows libraries dont work on linux. Write your own.
 
0 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux Header files not found Frank85 Linux - Kernel 16 11-27-2009 01:42 AM
Linux Header Files Roy-Svork Programming 8 08-01-2005 08:45 AM
Linux kernel header files cranium2004 Programming 4 03-04-2005 04:41 AM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM
qt-3.1.2 header and libraries...where are they? Hammett Linux - Software 1 11-10-2003 08:15 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration