What to install and how to run an executable file on Mac? - c

So I'm in terminal, and have a directory called CAPTURE on my desktop, I'm trying to run a program called 'testme'. I read that you need to have build-essential installed but I think that's only on Linux systems and I'm on a Mac so it wasn't necessary because it's already built in (I think). So, I navigated from ~ with:
cd Desktop/CAPTURE
Then, I tried running a bunch of different commands that I found while looking on the internet:
./testme
which returned zsh: exec format error: ./testme
xcode-select --install
which installed properly and I thought I could run the ./testme command but I got the same error as before. Then I tried navigating to the directory again and used
chmod +x ./testme
./testme
which also did not work. I've never run executables before so I really have no familiarity with these commands so they might be super wrong. If anyone can help me run the file properly, that would be much appreciated.

Since your question is tagged as C and Clang, and you are talking about build-essential, I will assume that you are attempting to build an application from source code.
Instead of build-essential, in macOS, you need Xcode. The Xcode CLI tools will work if the application is text-only or Curses, but you will need the entire Xcode IDE for any graphical application.
If running ./testme is telling you Executable format error is probably because it's a prebuilt executable, very likely a Linux ELF executable that will not run in macOS.
My suggestion is to try to build the software. Most C applications will build if you run make inside the directory. make is installed by default by Xcode. Other applications may need a third-party build system, such as CMake, but I do not know if that's the case.

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 correctly run Cuda toolkit in Ubuntu in the WSL (eventually to be used for YOLO)?

I followed the tutorial here from the Medium: https://medium.com/#GuruAtWork/setup-fastai-ubuntu-on-windows-10-44ca50b13a9
I was following it well until a MinGW was used for command lines. I am not sure how they went about doing this as the only way I could get nvcc to work is with sudo apt install nvidia-cuda-toolkit. However, this does not seem to complete the same thing as their tool kit is installed as if the exe was just run with Windows. However, that, of course, doesn't work with the Ubuntu. Let me know what you think, thank you.
AFAIK it's just not possible right now to do so from WSL. The link from Medium only sets it up for the Git bash prompt, which is not the same as WSL.

GDB on Mac OS Sierra, trying to uninstall and remove all files completely but can't

I should preface this by stating I'm working with Xcode on macOS Sierra 10.12.6.
I installed GDB with homebrew and it appeared to install fine until I tried to use it. In terminal it kept saying that it was not a valid command. (I'm new to C and was working with my professor. Even he was baffled when I tried to use it after downloading it in front of him). So later I tried to install it by creating the make file and still having problems. I then used homebrew again but to uninstall and reinstall, still having problems.
Now I'm at the point where I can't even run my C files when I use gcc to compile them. I simply get a statement that unable to open file. I've read someone suggest to sudo mv /usr/local /usr/_local and I'm notified that I don't have permission, even after entering in my password.
I've gotten every error when I try to remove all items belonging to gdb. I've gone as far as removing Xcode in hopes that I can do a fresh install of it all.
I'm at the point where I've begun looking into removing my macports entirely.
I'm looking for any advice into how I can try to start off from a clean slate. I need to use gdb on a project that is due and can't get this up and running. Please help talk me from a ledge!
EDIT:
I have used Sublime to create a simple Hello World file and it compiles and runs fine with gcc. So my project file has become corrupted somehow. At least I can calm down a bit. But I would still like to get this gdb issue figured out and install a fresh copy with everything old removed.
I'm working with Xcode on macOS Sierra 10.12.6
I need to use gdb on a project that is due and can't get this up and running
I don't know how to reinstall gdb on macOS, but be aware that gdb is broken on macOS Sierra as of now (at least debugging dynamic libraries), see Bug report.
So if you even get gdb correctly installed you can probably end up with nothing (gdb won't be able to debug what you want).
Try making your file executable using gcc -Wall -g $fileName.c -o $fileName. This will show all the errors that might exists. Secondly, if it doesn't work and you absolutely need to use gdb, using a VM of Linux(recommend Ubuntu if you're new to Linux or Mate) is a good alternative. You then have to just use sudo apt-get install gdb and even install gdb-dashboard git-hub gdb-dashboard if you want to do some serious debugging. That's the quickest fix that I can think of you are in a hurry. Btw good VMs are VirtualBox and Parallel Desktop(if you want to have access to your local files from the VM).

(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

Linux redhat kernel-headers

I'm trying to compile a c programming package (thc-ipv6-0.7) on Linux Redhat 2.6.9-42.ELsmp and it's complaining that it can't find "linux/string.h".
From google, I learned that this is part of the "kernel-headers" package.
If I do "rpm -qa | grep kernel"
It shows that "kernel-devel" is installed (which I think I need), but not "kernel-headers".
A "find / -name string.h" reveals string.h is in fact on the system, in many places, including "/usr/include".
I tried adding "-I/usr/include" to the make file, but got the same error.
My question is, do I need to install "kernel-headers", and if so, where do I find it, and what version?
Normally, you have to install the version of those headers which correspond to the version of the kernel run by the system on which you'll execute the program. In your case in you want to run locally, 2.6.9-42.
The message complains about "linux/string.h" and not "string.h", so you have add a directory having linux as subdirectory.
I'm not knowledgeable enough about redhat to know how to install them (probably an rpm command) and where they will be installed (with Debian and derivatives put them you have to use -I/usr/src/linux-kernel-version/include").

Resources