You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Xcode Question: How will I include conio.h permanently in Xcode?

I already put the conio.h file in Macintosh HD\Developer\Headers\FlatCarbon and yet Xcode still cannot recognize it. To remedy the situation, I just copy the contents of conio.h and paste them onto my code. It's very difficult to have to copy and paste all the time. How will I include the said file in Xcode permanently so that all I have to type is #include ? Please help. Thank you.

PowerBook G4, Mac OS X (10.4.10), 1 GB RAM

Posted on Oct 13, 2007 5:13 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 13, 2007 8:45 AM

The conio.h header is not available in Mac OS X by default. And simply adding the header to your project is only going to get you past compile time errors. You'll still fail during linking unless you have some library that implements the functions declared in conio.h.

A few quick searches indicates there is no conio for Mac OS X. See this message for example which implies that you can get similar functionality by using the curses library in OS X.

Steve
3 replies
Question marked as Top-ranking reply

Oct 13, 2007 8:45 AM in response to Lady777

The conio.h header is not available in Mac OS X by default. And simply adding the header to your project is only going to get you past compile time errors. You'll still fail during linking unless you have some library that implements the functions declared in conio.h.

A few quick searches indicates there is no conio for Mac OS X. See this message for example which implies that you can get similar functionality by using the curses library in OS X.

Steve

Oct 14, 2007 7:59 AM in response to Steve Herman1

"You can use the curses library by adding /usr/lib/libncurses.dylib to your project. If you look at the man page for getch ('man getch' in Terminal), you'll see that it's in curses.h. Just #include that header, link against the library, and it'll work."

-> How can I add /usr/lib/libncurses.dylib to my project? What does he mean by "link against the library"? I type #include <curses.h> in my code but what else should I do to "link against the library"?

"Other functions from conio.h might be tougher to implement, since ones like kbhit() just don't exist on Unix-like systems. A quick Google search for each API and either "Unix" or "Linux" should help you figure out how to implement them on Mac OS X."

-> I have lots of problems with my code. My clrscr() and getch() won't work and I also have kbhit() in my code which, according to Eric, doesn't exist on Unix-like systems. What to do?

Oct 14, 2007 11:00 AM in response to Lady777

Lady777 wrote:
-> How can I add /usr/lib/libncurses.dylib to my project? What does he mean by "link against the library"? I type #include <curses.h> in my code but what else should I do to "link against the library"?

When you build an executable from a compiled language (such as C, C++, Objective-C, and others) it basically involves two steps. A compile phase and a link phase. As a simple explanation...

Compiling takes the source code files you've created, checks to make sure they are syntactically correct and then produces _object code_ files for each of your source code files. At this point these object code files are not executable because they only include code for what _you have written_ and not any of the functionality provided by the OS.

When you #include a .h file in one of your source files it allows the compile step to verify that your use of functions defined in the .h file are syntactically correct. But it doesn't include any executable code for those functions.

Then the link step takes the object code files produced by the compile step and links them together along with object code libraries provided by the OS to produce your final executable file. To "link against a library" means that you add the (system provided) library to the list of libraries that gets used during this link step.

When you do a "build" in Xcode it does both a compile and a link for you. So it's possible to fail during the compile step if your source code contains errors. But it's also possible to successfully compile if your code is syntactically correct but then fail during the link step if the linker can't resolve references to external functions.

To add /usr/lib/libcurses.dylib in Xcode go to "Project -> Add to project...". Since the /usr directory is typically invisible in Finder you probably won't see it in the Add window... instead, while the Add window is open press Command-Shift-G. This will open a "Go to folder" window. Type in /usr/lib and click OK. You should then see all the libraries available in /usr/lib. Select libcurses.dylib and click the Add button.

Steve

Xcode Question: How will I include conio.h permanently in Xcode?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.