Installing gdb on Mac OSX 10.9 - c

I'm trying to install gdb on mac and seems to be hitting one issue after another. Well for starters I've X-Code command line tools installed on the system. When I initially ran gdb, I'd get
gdb: command not found
k so I go ahead and install it
brew install gdb
It does the installation and comes up with the following issue
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/info/annotate.info
/usr/local/share/info is not writable.
You can try again using:
brew link gdb
So I try again,
brew link gdb
Linking /usr/local/Cellar/gdb/7.8...
Error: Could not symlink share/info/annotate.info
/usr/local/share/info is not writable.
I try giving write permission to the folder
cd /usr/local/share/info
Thus I do what it wants me to do,
| => chmod +r annotate.info
chmod: annotate.info: No such file or directory
The saga continues, now where I stand is
| => brew install gdb
Warning: gdb-7.8 already installed, it's just not linked
How can I link gdb and get it working. Any help appreciated.

Related

Homebrew Mac M1 can't find installs

I just switched to a M1 MacBook Air and I'm having trouble with Homebrew. The installation went fine I think, and then I added it to my path with the given commands:
Run these two commands in your terminal to add Homebrew to your PATH:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/xxx/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
I also did brew install cunit and then when I typed brew list CUnit was listed there so I'm assuming the brew install of cunit worked.
But when I run my C test code this is what I get:
test/test.c:3:10: fatal error: 'CUnit/Basic.h' file not found
#include <CUnit/Basic.h>
^~~~~~~~~~~~~~~
1 error generated.
make: *** [test_compile] Error 1
I have been sitting with this for three days, called Apple support, searched every page related to this and still can't find a solution that works.
Has anyone had the same problem? PLEASE help
Homebrew installs into /opt/homebrew by default on M1 Macs, and no longer links into /usr/local by default (to prevent clashes with Rosetta library installs). This means that include files and libraries can't be found without explicitly telling the compiler/linker where your Homebrew packages are installed.
The easiest way of doing this is by setting the CPATH environmental variable before compiling:
export CPATH=/opt/homebrew/include
Add the above line to your shell profile (.zprofile for zsh, or .bash_profile for bash) and it will be used in all future compilations.
For dependencies which also require shared libraries, you will need to also signpost the location of Homebrew's new lib path:
export LIBRARY_PATH=/opt/homebrew/lib

Compiling through macOS Terminal, fatal error: stdio.h: No such file or directory

So was trying to compile a c file (via a makefile) and got the "fatal error: stdio.h: No such file or directory" . This compiles on just fine via cygwin and a remote linux box just not my mac (so the files are okay).
I have installed the mac command line tools as mentioned in this question. When I do gcc --version I am getting 5.3 but if i do brew info gcc i get 8.2. When I do a find through terminal I can the file, so not sure what is up.
If you run:
which gcc
you will get /usr/bin/gcc which is the compiler supplied by Apple as part of macOS.
Presumably, since you mention homebrew, you mean to use the compiler installed by homebrew. So, you need to look in /usr/local/bin and see what homebrew has installed:
ls -l /usr/local/bin/gcc*
lrwxr-xr-x 1 mark admin 29 17 Sep 10:53 /usr/local/bin/gcc-8 -> ../Cellar/gcc/8.2.0/bin/gcc-8
So, the answer to your question is:
firstly, you need to have /usr/local/bin at the start of your PATH, and
secondly, you need to use the following command to compile:
gcc-8 main.c -o main
try running following:
xcode-select --install
See:
GCC fatal error: stdio.h: No such file or directory
for details.
With Mojave and XCODE 10, the problem is that the "include" folder is no longer automatically included when you install the command line tools. Instead, you need to do an "open" on /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
That solved the identical problem for me, anyway.
I ran into this issue and this is how I resolved it.
softwareupdate --all --install --force
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
Basically developer framework is likely to be broken. But simply running xcode-select --install may not work because it will say the xcode developer tools are already installed (despite its broken status). So I had to completely wipe out any existing installation and install the developer framework again.
FYI if everything is installed correctly, the header files should be found at:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include

gcc download on windonws ubuntu bash IP address fetch returns error

I've attempted to gcc a test.c file on my windows linux bash subsystem, gives me the "gcc not installed" so i go and try to install gcc using
sudo apt install gcc
so i'm using the root "sudo" so permissions should be granted, and i've tried with a few different variations of the install command
When I run the above the command I get the a series of errors saying that the ubuntu site's IP address couldn't be located (full can be seen here)
I think the Ubuntu server's IP has changed? or moved, I mean it literally gives 404 errors. This what i suspect, I don't know for sure, is there a way to download the gcc compiler? I don't know of any other routes to get the gcc compiler on my bash subsystem.
It's a 404 error (file not found). apt is connecting to the IP in question, it just doesn't have that file. Update your cache (sudo apt update), then try installing again.

How to link the Valgrind 3.11.0 in my MacBook Pro (El Capitan)?

First of all, my Mac OS version is 10.11.3 (El Capitan).
So, I am learning c through http://c.learncodethehardway.org/book/. It's a tutorial by Zed A. Shaw. On that tutorial, he asked the reader to instal the Valgrind. The steps are as below:
# 1) Download it (use wget if you don't have curl)
curl -O http://valgrind.org/downloads/valgrind-3.6.1.tar.bz2
# use md5sum to make sure it matches the one on the site
md5sum valgrind-3.6.1.tar.bz2
# 2) Unpack it.
tar -xjvf valgrind-3.6.1.tar.bz2
# cd into the newly created directory
cd valgrind-3.6.1
# 3) configure it
./configure
# 4) make it
make
# 5) install it (need root)
sudo make install
So, I did as above and got stuck at step 4. If I am not mistaken, the command line said no target to be make (something like that). I'm realised then that it is not the latest version of Valgrind, so by using exactly the above steps, I've managed to install the latest one. I managed to go until step 5 although sometimes there are some negative messages from the command line during installation.
The problem is, whenever I enter valgrind, the command prints -bash: valgrind: command not found. Then through brew doctor, this message is printed:
Warning: You have unlinked kegs in your Cellar
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
valgrind
When I type brew link valgrind, this message is printed out:
Linking /usr/local/Cellar/valgrind/3.11.0...
Error: Could not symlink include/valgrind/callgrind.h
/usr/local/include/valgrind is not writable.
I even tried brew install --HEAD valgrind and this message is printed out:
Warning: valgrind-3.11.0 already installed, it's just not linked
What is happening? How can I fix this? Is this thing happened because of my mistake in trying to install an outdated Valgrind before by using the make command (although the make command cannot be executed at that time if I remember correctly)?

GCC fatal error: stdio.h: No such file or directory

I'm trying to compile a program in C on OS X 10.9 with GCC 4.9 (experimental). For some reason, I'm getting the following error at compile time:
gcc: fatal error: stdio.h: No such file or directory
I then tried a simple Hello World program:
#include <stdio.h>
int main(int argc, const char *argv[])
{
printf("Hello, world!");
return 0;
}
Again, upon running gcc -o ~/hello ~/hello.c, I got the same error. I'm using an experimental version of gcc, but it seems implausible that there would be a release which generated errors upon importing stdio. What could be causing this issue, and how can it be fixed?
macOS
I had this problem too (encountered through Macports compilers). Previous versions of Xcode would let you install command line tools through xcode/Preferences, but xcode5 doesn't give a command line tools option in the GUI, that so I assumed it was automatically included now. Try running this command:
xcode-select --install
If you see an error message that developer tools are already installed (and still header files can't be found), wipe out any existing one to do a fresh installation:
sudo rm -rf /Library/Developer/CommandLineTools
Ubuntu
(as per this answer)
sudo apt-get install libc6-dev
Alpine Linux
(as per this comment)
apk add libc-dev
Mac OS Mojave
The accepted answer no longer works. When running the command xcode-select --install it tells you to use "Software Update" to install updates.
In this link is the updated method:
Open a Terminal and then:
cd /Library/Developer/CommandLineTools/Packages/
open macOS_SDK_headers_for_macOS_10.14.pkg
This will open an installation Wizard.
Update 12/2019
After updating to Mojave 10.15.1 it seems that using xcode-select --install works as intended.
ubuntu users:
sudo apt-get install libc6-dev
specially ruby developers that have problem installing gem install json -v '1.8.2' on their VMs
I know my case is rare, but I'll still add it here for someone who troubleshoots it later.
I had a Linux Kernel module target in my Makefile and I tried to compile my user space program together with the kernel module that doesn't have stdio.
Making it a separate target solved the problem.
I had the same problem. I installed "XCode: development tools" from the app store and it fixed the problem for me.
I think this link will help:
https://itunes.apple.com/us/app/xcode/id497799835?mt=12&ls=1
Credit to Yann Ramin for his advice. I think there is a better solution with links, but this was easy and fast.
Good luck!

Resources