How can I add graphics.h library on my mac? - c

I want to draw a rectangle using a C program. So I was trying to use the graphics.h header. But the GCC compiler gave me a error saying that the library could not be found.

graphics.h is a header that define functions for libbgi (Borland Graphics Interface)
Unless you have a Borland compiler of some sort installed on your Mac (if that's even possible), I think you'll end up having to use other graphic libraries, or install a Windows/Linux Virtual Machine on your Mac and then run/compile your code inside it.

graphics.h is not a standard C header and is probably a part of a custom library. If you can track down that original library and provide more info, we can probably help you get it set up.

Related

How to do proper cross compilation for C on Mac?

I am trying to compile C code on a Mac (M2), with as target windows. I have tried this in the past on linux, with success, but there doesn't seem to be a straightforward way on Mac.
On the linux machine I was able to get a whole range of cross compilers from GNU, they had the system headers built in, so it was really really simple, something like
gcc-...-mingw main.c -o main.exe
would create a simple windows executable. From there it was as simple as moving the main.exe file to a usb drive or cloud to and transfer it to a windows machine to run it. Really simple!
For Mac I have found some resources about Clang, but you need to provide the system headers yourself, which I have no idea how to do. And there is more setting up, which I don't want to get into if there is a solution as simple as the one I just showed.
My question: What is the way to compile a C program on a Mac with the target system being windows, or even Linux?
Thanks for the help!
Visual Stdio Code has support for various C compilers native for M2. It isn’t a full IDE, simply a code editor with extensions.
You should be able to download the plugins/extensions you need via the GUI interface and let it manage the environment.

1- Make a library in C 2- Call and use it in MASM

The teacher asked to do the two tasks given in the title,and the only hint he gave is that the library file will have extension ".lib" . I have tried to make a static library using Code Blocks, and it has ".a" extension instead of .lib. Now how do I call and use this library in MASM, I have no idea. Please Help!
A .a file is a static library on Linux / UNIX. Code Blocks is cross-platform, but often found on Linux, so I wouldn't be surprised if you were running it there.
A .lib file is a static library on Windows. MASM is the Microsoft (Windows) assembler.
You're not using the right toolchain for your platform. Or potentially, you're not even working on the right platform.

Can I use OpenGL for graphics in my C program?

I want to use a library for making some shapes in my C program. Can I use gl.h in my C program if I install it? Will it be compatible or is it designed for languages other than C?
You normally dont install gl.h. It is just the header to a library. The library-implementation should already be provided by your OS/drivers eg in some .DLL-files. The header gl.h can just be #include'ed so you can call the functions.
You did not tell us your OS, but there are tutorials for each, eg for windows: have a look at the tutorials on the right side of http://nehe.gamedev.net/

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.

Resources