Where is my "stdio.h" in Mac? - c

I know that Mac OS X is a Unix-based system. And I heard that C standard library such as stdio.h, is located in /usr/local/include or /usr/include. But there is not any kind of library in this directory. I use Terminal to search this directory and I also use command like find ./ -iname "stdio.h", but nothing comes out. However, strangely enough, gcc -test.c -o test command works out. How did it happen? I want to know where my C library is located.
p.s I also use Xcode, too. Is it related with this application? help me!
And I have AWS EC2 linux server, and it has both libraries that i refereed above.

If you have Xcode but have not installed the optional Command Line Tools package then the standard includes and libraries may not be found in the usual place. Try:
$ find /Applications/Xcode.app -name stdio.h
and you'll probably see something like:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/tr1/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/4.2.1/tr1/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/4.2.1/tr1/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/sys/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1/tr1/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h
However you might want to install the Command Line Tools package if you plan on doing any non-Xcode (i.e. command line) programming. You will then see the usual headers and libraries in /usr/include and /usr/lib.

If you don't have Command Line Tools installed you can run:
xcode-select --install
A dialogue box opens for you to accept the license agreement and so on.
(This was missing from the above responses.)

create/update a symlink for /usr/include to have the libs detected:
sudo ln -sf /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include /usr/include
The above path can be found by searching for stdio.h
find /Applications/Xcode.app -path '*/usr/include/stdio.h'
I have to do this with every XCode/MacOS SDK update, Faced this today with the XCode 7 upgrade.
Once the command line tools are installed, they cannot be re-installed with xcode-select, so the path may not be updated with a Mac AppStore upgrade.
Uninstalling & Reinstalling XCode and then running xcode-select --install might update the path, but is an overkill.
Some posts also mention xcode-select --switch /Application/Xcode.app, but I didn't have much luck with it.

The root reason is missing the /usr/include folder, installing command-line tools sometimes will not automatically add it.
Install the package at
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

In my laptop it appears in many locations like /usr/include/stdio.h and /usr/include/sys/stdio.h and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h.

If you already built your locate database, you can use
locate stdio.h
If you haven't already, build it. The locate command is awesome!

Due to Apple's new System Integrity Protection (SIP), you will run into this error when attempting the solution of creating/updating a symlink to /usr/include
ln: /usr/include: Operation not permitted
Instead of disabling SIP, the better way to do it is to create symlinks in /usr/local/include instead, e.g.
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/* /usr/local/include/
This works for people who have already installed CommandLineTools and was unable to find stdio.h inside /usr/include

In the folder
Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
or similar.

I have installed "CommandLineTools", and the "stdio.h" file exist in both Xcode and CommandLineTools diretory.
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdio.h
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdio.h

This is my path for C/C++ library in M1 Mac 2022
/Library/Developer/CommandLineTools/usr/include/c++/v1

Related

Codelite not running C programs

Everytime I try to build and run a program, including the standard 'Hello world!' nothing happens, I get:
==== Program exited with exit code: 0 ====
Time elapsed: 000:00.000 (MM:SS.MS)
Press any key to continue...
At the bottom it says:
'ming32-make' is not recognized as an internal or external command, operable prgram or batch file.
I have Codelite version 16 on Windows 10. I also have MinGW installed to C: and have edited the Environment variables to include C:\MinGW\bin
However, in command prompt gcc --version shows me the gcc version in C:\Users\me> and not C:\MinGW
I don't know if this is relevant or not.
All the other results seem to suggest a compiler not found problem, but this does not seem to be my case. Thanks in advance.
This is what I have installed at the moment. Can I get 'make'from one of the other files?
The Installed files
Looks like you either don't have ming32-make.exe or it can't be found.
Also I notice you still use old MinGW. I would recommend switching to newer MinGW-w64 (which supports both Windows 32-bit and 64-bit).
The standalone build from https://winlibs.com/ does include ming32-make.exe, and since you can just unzip it (no installation needed) you can try it without removing the old MinGW. Just make sure you don't have anything in your PATH variable to avoid running programs from the wrong location.
ming32-make.exe is either not installed or can't be found on your Environment variable PATH.
No, there is no mingw32-make in that bin folder. When I used the Installer originally I only selected: mingw32-gcc-g++-bin although there were other bin files. Where can I get it?
mingw32-make is outdated.
See How to compile makefile using MinGW?
If you are having problems with mingw, I would recommend using MSYS2 or a package manager like Chocolatey.
Just get rid of the previous installation first. Not mandatory but prevents confusion and storage drain due to multiple copies of mingw.
To install MinGw using chocolatey, run cmd as admin and use
choco install mingw
For make
choco install make
What worked for me was also installing mingw32-base-bin from the Installer (see second option in image in the original question).
The installation tutorial I was following did not mention installing this.
I've decided to leave this here as an answer in case someone else runs into a similar problem.
MSYS is a good option for compilers in recent CodeLite or VS-Code installation. https://www.msys2.org/.
Once you downloaded the compiler using the following steps from the installer but still have the problem with the make then follow these steps:
Reopen the MSYS2 terminal from your windows if that is previously installed.
Run the command pacman -S --needed base-devel mingw-w64-x86_64-toolchain
You will be asked to select the option from the list. You should select the option which refers to mingw-w64-x86_64-make.
Once the installation is successfully done, then open CodeLite settings->Buid Settings and check your Make file location. If that is empty or showing an unknown location then click the three dots at the very right of that box. The browse and navigate to location or where you installed the make by pacman. In my case it is C:/msys64/usr/bin/make.exe.
Click Apply and Save.
Now it might be needed to create a fresh workspace and re-run your code.

How to check C libraries installed without root access?

I am working on a school project in a limited environment (archlinux) where I don't have root access. The subject says that I am allowed to use all libraries that are already installed. I am coding in C using gcc.
How to get a list of all those libraries ?
For those libraries managed by the pkg-config utility, the following command will show all installed libraries:
pkg-config --list-all | less
However, not all libraries are so managed so you may be forced to go through the /usr/lib and /usr/local/lib directories.
As noted, not all libraries necessarily use pkg-config. Given that this is ArchLinux, as a fallback you could learn to use the package manager, to list the installed packages. That is called pacman.
Anything that is installed as such on ArchLinux would be part of a package.
The query options can show you all of the files installed for given packages:
To list all files for a given package, use pacman -Qlpackage_name
To list all packages, use pacman -Q
(scripting that, to list all ".so" files which are installed, by package name would be an interesting exercise).
ls /lib /usr/lib /usr/local/lib

Can't compile libcgcrypt-1.6.1 - can't see libgpg-error

[...]
checking for GPG Error - version >= 1.11... no
configure: error: libgpg-error is needed.
See ftp://ftp.gnupg.org/gcrypt/libgpg-error/ .
Username#Computername /cygdrive/f/coding/sourcecode/libgcrypt-1.6.1
$ gpg-error-config --version
1.9
As you can see I do have gpg-error installed, or so it seems.
Perhaps the problem is that the source directory is on F:\ while Cygwin, Windows and everything else are on C:\?
I've found the same question asked before on http://lists.gnupg.org/pipermail/gnupg-users/2009-May/036486.html -- unanswered...
Cygwin 1.7.31, Windows 8.1 x64, libgcrypt-1.6.1 and libgpg-error is 1.9, naturally.
Thank you in advance, please tell me if I should provide additional information.
Sorry for the silly question; it appears I hadn't set up LD_LIBRARY_PATH and LIBRARY_PATH correctly. If you are having a similar problem, it is worth checking your CPATH and PATH as well, while you're at it.
If you're using Cygwin like me, be sure to add -
/usr/local/lib to LD_LIBRARY_PATH and LIBRARY_PATH,
/usr/local/include to CPATH,
/bin and /usr/bin to PATH (and put those before .../windows/system32).
After that everything should install.

"'portaudio.h' file not found" error in XCode 5.1

I've downloaded the portaudio codebase and compiled it fully with source, and installed it to my system with these commands:
./configure
make
sudo make install
But XCode is complaining to me, even when I put -lportaudio in the Other Linker Flags for the project settings.
I've researched this problem and tried whatever I could find on Stack Overflow, but there was no decisive answer that would work for me. Any advice on how to fix this?
I'm using an older version of XCode and haven't bothered looking at how the interface might have changed in the newer versions, but this is generally solved for me by modifying the User Search Paths under your project settings. Look at the screenshot, add /usr/local/include to Header Search Paths and make Always Search User Paths "Yes." That should do the trick
Edit:
One more thing to note, this is only /usr/local/include because that's the default install directory for the portaudio.h file in the portaudio build (as it is with many libraries).
If you have a different prefix other than /usr/local/include, add that instead.

(Mac OSX) Adding libraries to C -specifically gnuplot

I am a begineer trying to get code in C. I am working on a Mac and using xcode. My only past experience has been with java using eclipse and everything was pretty straight forward. I have almost no experience with terminal.
I am required to learn a bit of C for a project I will be working on and the learning of syntax is coming along okay, but I am at a point where I need to include some libraries in my c program. Specifically I am attempting to make plots with gnuplots.
I have downloaded gnuplot-4.6.3 from their repository and I do not even know how to install the files. I have been looking around and have tried using terminal to use the ./configure command when I am in the gnuplot-4.6.3 directory. But I really don't know what I am doing so I don't even know where to go next or what to do next.
Sorry if this is so trivial, I honestly just have never done this before and I cannot find a good tutorial on what to do.
Thanks for any help you can offer.
I would recommend using MacPorts for installing third-party tools and libraries. It knows the dependencies required and will install them as part of the installation.
Download it from macports.org.
Install it, and allow it to modify your ~/.profile so that /opt/local/bin is in your $PATH (any issue then just do export PATH=/opt/local/bin:$PATH from the command line).
sudo port selfupdate
sudo port install gnuplot
Now that will install the library into /opt/local/lib with the include files in /opt/local/include, so now just add that library to your Xcode project. Select the target and in the Build Phases tab open up the Link Binary With Libraries and press the + button and select Add Other. Now find /opt/local/lib/libgnuplot.a (I am assuming that's what it's called; I don't have it installed my self):
Now add /opt/local/include to your Header Search Paths so the compiler can find the gnuplot header files. Select the target and in Build Setting type in "header search" in the search box. Now double-click on the Header Search Path in the target column (or the project column to the right) and add /opt/local/include:
It's fine! You're learning then! Keep up! When I hit this kind of problem you may want to learn about the basis for linux gcc/g++ compilation and linking processes. Then you should learn Cmake and Automake, which are basically packages to configure projects before compiling building.
A typical (good) project in Unix systems build with commands
./configure
make
sudo make install
or
cmake CMakelists.txt
make all
sudo make install
That's what you need to do after downloading a source tarball online to install unix programs.
Now since you are using Mac, there are so-called package installers, one which is macports and homebrew. I personally suggest homebrew than macports here (I've tried both, although macports still outnumber homebrew with the number of repos, homebrew has the newest support, especially when upgrading to a new OS). So to install homebrew you can do
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Execute that in your terminal (see http://brew.sh/) for more information.
Then you could simply install GNUplot by
brew install gnuplot

Resources