(Mac OSX) Adding libraries to C -specifically gnuplot - c

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

Related

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

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.

How to setup a C development environment on Linux for GTK+?

I'm new to programming C in Linux. I like to make GUIs with GTKlibs. The only problem is that im unable - and not only with gtk - to install these packages correctly. I have problem to include the librarys like #include<gtk/gtk.h> if I have installed it with sudo apt-get install gtklib-3-dev.
On compile time it sais everytime that the file is missing and so on. I have read the option to put dpkg configs and cflags to the compiler, but that doesn`t work either. How linux is managing the include folder and why do libs like gtk have an upperfolder with the version on it like gtk3 etc.. This is the problem that leads to missing files.
The exact package name depends on your Linux distribution. If you're using Ubuntu, then the right command is:
sudo apt-get install libgtk-3-dev
You may then check if the development packages are detected with something like:
pkg-config --exists gtk+-3.0 && echo "Installed" || echo "Not installed"
To learn how to build your application, follow the instructions of the official documentation on How to compile GTK+ applications.
Finally, instead of doing the gcc calls manualy, you can automate them by using a build system like the Meson build system. There's a tutorial on how to build a simple GTK+ application with Meson.

What is the right way to install header files from some package?

I want to build some package from source (e2fsprogs to be more concrete) and install its header files to my system. After that I will delete the build tree so it will not be accessible anymore. What is the right way to do this?
When I want to install program, I make simply:
$ ./configure
$ make
# make install
What are the equivalent actions when I want to install headers?
For e2fsprogs, quoting verbatim from the INSTALL file shipped with the sources:
7) Install the include files and libraries
You can run `make install-libs' to install the include files and
libraries. Please note that this installation is not needed for the
programs to work. It is only needed if you expect to develop other
programs using the libraries or if you want to compile other program
using these libraries (like the 4.4BSD dump and restore port).
More generally though, when I want to find out what is the 'proper' way to install something that has worked for others, I look at:
What the package looks like, in my favourite distro
How the package is built for my favourite distro

How to set up libusb on Mac OS X?

I'd like to try to make a user-space device driver using libusb on Mac, but I'm confused where to start. In the SDK installer (which I got from http://www.ellert.se/twain-sane) it said something about examples which I couldn't find anywhere on my computer.
Could anyone please describe how do I set up libusb for development on OS X? May I use Xcode? What should I include in my code?
brew install libusb-compat
Working on OSX Yosemite 10.10
Easiest way to do this:
brew install libusb
Homebrew is amazing and I recommend it for all developers that use Mac.
I tried to install the SDK from the aforementioned website and couldn't find a trace of it once the installer finished. Though I did find some libusb items at /usr/local/Developer/SDKs/MacOSX10.6.sdk/usr/local/ I'm not sure it came from that installer as I couldn't find any examples, just libraries and they were labeled as libusb0.1.4.
On the other hand, since you asked your question with the macports tag, I'd suggest you use that to install libusb as it at least puts everything in a known location:
/opt/local/var/macports/software for install files
/opt/local/lib for libraries
/opt/local/include for header files
If you've never used macports then once you have macports installed then you can install libusb using
sudo port install libusb
to install libusb1.0 or
sudo port install libusb-legacy
to install libusb0.1.12.
Then you can create a project in Xcode and link to the libusb-*.a library contained in /opt/local/lib (in my directory my library file is called libusb-1.0.a since I have libusb1.0 installed).
I don't have much experience using Xcode so I can't help you any further down this path. Personally what I've done so far is use a Python wrapper called pyusb to do some quick experimentation with libusb as I don't have to do IDE setup or library/include file setup with Python.
UPDATE: Poking around the macports install directory for libusb, I didn't find any examples included which was a bummer. If you've gotten this far then I'd suggest going directly to the source for libusb, download and unpack the tar file, and building the code that's in the example directory. Sorry for the roundabout way of getting libusb examples but I've really come to appreciate the organization macports imposes on installations which saves me quite a bit of future pain (like when I want to uninstall).
once libusb is installed using following command:
brew install libusb
or
brew install libusb-compat
link libusb to the build system using
brew link libusb
to be able to configure any project depending on libusb, use pkg-config:
pkg-config --cflags libusb-1.0
and
pkg-config --libs libusb-1.0
before calling any ./configure

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