VS2008 Missing C/C++ Header Files - c

So, I'm working on some network programming in C, and it would seem that I am missing a bunch of standard C/C++ header files. For example, sys/socket.h is not there. A few otheres are missing too like netdb.h, and unistd.h. Is there a pack I need to install to get these on windows?
Thanks

All these headers are from POSIX, not ANSI C, or ISO C++. You won't find them in Windows without installing some sort of compatibility layer, like Cygwin, or porting your application to Windows API, or use some macros and wrappers to map similar functions (i.e. #define strtok_r strtok_s).

none of those are standard c or c++ headers. On windows, socket definitions are in winsock2.h

you probably won't find it because it is a commonly used linux header file. You can find it in linux-libc-dev, if you really want it.

As others said, you're using the POSIX headers and definitions for Socket. Check out MSDN for the headers and structures that are defined on Windows: http://msdn.microsoft.com/en-us/library/ms740506.aspx. The calls are pretty much the same, but this will give you all the microsoft-specific syntax.

Related

Why the use of "conio.h" is not good habit of programming?

I have attended many online coding competition, they usually mention the note that #include<conio.h> means conio.h header can not be used.
I am not aware about all functions included by this header but curios to know that why it's not a good programming habit?
If anybody can explains some of it's functions should not be used.
example clrscr().
Well, conio.h is platform-specific. If you try to compile on Linux, your code will probably not compile. Also - using functions to manipulate the console window make your program less reusable than if you were using just standard input and output (you cannot redirect the stdin/stdout so easily).
If you are making rich console applications, you can instead use cross-platform libraries, such as ncurses.
It's not standard
[...] it is not part of the C standard library, ISO C nor is it defined by POSIX. 1
Some compilers support it but they are platform depended and it's hard to write a portable code between them.

How to add a header file to the c project?

Am using a Dev c++ compiler, to compile a c code. (I am a beginner)
When I compile, it says 'some' header files are missing.
How can i include those header files in my system, so as to be utilized by the program??
Thanks
A header such as <sys/sem.h> which is used for the function semget() among other things, is not generally available in Windows. It's a POSIX header, and Windows does not implement the POSIX standard out of the box.
You should maybe look at the Win32 API instead, for instance a function like CreateSemaphore().
The problem is that you are trying to use the Linux API on Windows. Here is what is going on: Every operating system has its own set of libraries for programmers to use to make programs on that platform. In this instance, you are attempting to use Linux libraries on Windows. Windows doesn't have a code location called sys/ipc or sys/sem.
Furthermore, since you said you are a beginner, try finding another tutorial. sys/ipc.h and sys/sem.h are not for beginners, are are libraries typically used for communication between processes. These concepts are way beyond you right now haha :P
Here is a better place to start: http://www.cprogramming.com/tutorial/c-tutorial.html

Visual Studio cannot find some C libraries, such as stropts.h

I'm attempting to compile a sample c file that was given to me, but unfortunately, it's missing several libraries as some of the include files cannot find them. Namely: stropts.h, netdb.h, sys/socket.h, sys/ioctl.h, netinet/in.h, pthread.h, and unistd.h.
I've researched where I could fix these problems, but surprisingly there have been little to no results on this problem strangely. The Visual Studio command prompt isn't able to compile it until I can find these libraries. Anything I need to download/ link to fix this?
Those header files are not part of standard C or C++. Do not attempt to download the headers from other sources; even if you can get them to compile, they won't link properly since you don't have the implementations of the functions declared therein in a static library or DLL.
The simple fact of the matter is that the code you're trying to compile was written for Unix/Unix-like systems and it's not portable to Windows. You'll need to either significantly rewrite the code to use the equivalent Windows functionality or a 3rd-party platform-independent library (e.g. Winsock or Boost sockets for sockets), compile it on a Unix system (you could use a virtual machine if you want), or use a Unix compatibility layer such as Cygwin.

Where can I find the source code for all the C standard libraries?

I'm looking for the whole source code of all the C standard libraries. That said, I'm looking for the source code of stdio.h, stdlib.h, string.h, math.h, etc... I would like to see how they were created. I think that it depends from platform to platform, but Linux or Windows one will be welcomed.
If you want the actual implementations, as everyone else has assumed you don't, many Linux distributions currently use glibc to implement the C standard library. Common alternatives include musl libc, diet libc, uClibc, and Bionic
PJ Plauger wrote a book about the standard C library. Includes references from the (now dated) standard, and source code.
Microsoft Visual Studio generally has the system headers under <InstallDir>\VC\include, and the source, if installed, is under <InstallDir>\VC\crt\src.
Whether its installed with an IDE or you have installed explicitly, you have to look in the directory "Include" in respective location.
Ex: I use MinGW. So, I would go to
c:/MinGW/include to find those header files. Similarly, for an IDE (say Dev-cpp), you need to go to c:/dev-cpp/include.

Can I use winnt.h in Linux?

My program is written in C. I want to use library winnt.h, but I don't use Windows anymore.
Seems like a strange question; you should probably clarify which function(s) you actually need from winnt.h so that you can learn the Linux equivalent. winnt.h isn't really a general purpose "library", it's just an interface to built in Windows-specific functions.
With that as a major caveat, you may get some degree of what you want by attempting to run your app with the help of Wine. See http://www.winehq.org/ If you're just trying to run an existing app, that's may be a reasonable solution. If you're trying to make a Linux version of your app, though, that won't help you very much.
No, well you could but it's not going to do any good - the.h file just declares functions that are defined in libs that are only on windows
No. You can't.
winnt.h contains lots of macros that depend on a Windows environment and a lot of function declarations that only exist in Windows-specific libraries. So, it's not really useful (or possible) to use winnt.h on Linux.
That said, you can use Winelib, which includes most of the functionality exposed by those Windows-specific headers, and you can get those features by linking your program with Winelib. In general, this is probably not a good idea, because Winelib is relatively unstable (the functionality of a given API function may be absent, incomplete, buggy, or incompatible compared to the native Windows version). It is a much better idea to look for a Linux-native alternative to what you need.
What parts of winnt.h do you want to use? Of course, if you need some nice macroses or type definitions from it, you can freely copy it to your own header file (of course, with dependencies). But if you include all winnt.h file to your program in linux environment, you will get tons of error messages. One of the reasons for it is pronounced by Martin Beckett in his reply.

Resources