I was wondering if anybody here is familiar with the "libelf by example" book.https://www.dbooks.org/libelf-by-example-1587/read/
I was trying to run prog2.c but I couldn't find the header vis.h (header it's used in chapter 3 and 5)
I downloaded the libelf library from the sourceforge link https://sourceforge.net/p/elftoolchain/wiki/Home/ I also tried to googled it up but I couldn't find anything relevant. I was wondering if it's been substituted by another header in future versions.
I couldn't find the header vis.h
The author appears to be using this vis function.
Try changing #include <vis.h> to #include <bsd/vis.h>.
On my system, this file comes from libbsd-dev package. It is likely that you'll need to link against libbsd.so to get the definition of vis.
Related
I'm just getting my feet wet in C with some work in GStreamer, but seem to already be stuck.
I'm compiling the project in X Code using GNU99. The <time.h> header file that is part of the GStreamer code has no reference to time_t, which is used by some of the files.
Therefore I'm seeing:
/Library/Frameworks/GStreamer.framework/Versions/1.0/Headers/glib/gbookmarkfile.h:171:11:
Unknown type name 'time_t'; did you mean 'size_t'?
Do some C versions have varying header files for <time.h> that have done away with the time_t type? If so, is there a workaround?
Edit:
Looks like it has something to do with how XCode is searching for the <time.h> header file.
It should grab it from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h, but it's instead using one from FFmpeg
Under header search paths, I see this:
/Library/Frameworks/GStreamer.framework/Versions/1.0/Headers
This setting is directly from the tutorial download
My workaround solution was to add
#include </Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/time.h>
to the FFMPEG time.h file.
Your path to the proper time header file may vary.
I'm trying to include a folder that contains a combination of around 60 .h and .hpp files. This folder contains libraries for programming robots with a Wallaby (a mini-computer-like device) for Botball competition. include is located in the same place as main.c (inside code). Up until now, this is what my header for including libraries looks like:
#include "../code/include/accel.h"
Just like accel.h, I have 60 other .h and .hpp files inside include. So, coming to my question, do I need to type out all the 60 header lines? or is there a way to include the include folder.
I'm using Clion for this project, if I can't include the folder itself, does anyone know of a shortcut in Clion to include all the files in include.
I was also thinking of using some sort of placeholder for the folder name and only specify the file type. So, for example: #include "../code/include/(generic placeholder name).h". I have no clue if something like this exists.
I would also request you to keep in mind that I'm a beginner to programming, so please keep your answers simple.
This is just for some extra info:
The Wallaby is a mini computer to which you would connect your sensors, motors, servos and cameras in order to control a robot for the Botball competition. Usually, one can connect to the Wallaby either via Wifi Direct or a cable and write programs on it directly through an online interface (not entirely sure of the word for it, but you just type in an IP address in your browser and it brings up an interface where you can make projects and code). All the code written in that interface saves directly onto the Wallaby. Here the default include statement is #include <kipr/botball.h>, so I'm assuming that botball.h (which is located on the Wallaby's storage) has all those 60 libraries consolidated in it. I got the include folder that I'm using from GitHub. This link was provided to me by one of the Botball organisers. So the main point in me trying to download the library is so that I can write and successfully compile code even when I'm not connected to the Wallaby. Hope this provides some relevant context.
Thank you for your answers!
What I'd do is
Create (maybe with scripting tools or a specific program) a "all.h" file which includes all the other header files
#ifndef ALL_INCLUDED
#define ALL_INCLUDED
#include "accel.h"
#include "bccel.h"
//...
#include "zccel.h"
#endif
Include "all.h" in your main file
#include "../code/include/all.h"
You can create "all.h" automatically every time you build your code.
CLion is an IDE for Clang and GCC. These compilers are instructed to search paths for include files by specifying -I<path> command line arguments. Any number may be specified, and they are searched in the order given, and the first match found is the file that gets included.
I am not familiar with CLion specifically but no doubt it has a dialog somewhere where you can set header file search paths.
Edit: It seems that CLion may not make this so straightforward. I understand that you have to add then via CMake: https://cmake.org/cmake/help/v3.0/command/include_directories.html#command:include_directories, but after that, the IDE will not recognise the header in the editor and will warn you of unrecognised files and will not provide code comprehension features. I believe it will build nonetheless.
I found a pacman project in github where a file conf.c includes a header file #include "ini.h" where ini.h contains only a single line (i.e no #include statement):
//ini.h
../common/ini.c
I have never seen anyone doing this before! It seems a bit hackish/rough around the edges. My questions are:
Is this legal C?
Is it portable?
Is it recommended?
I would have assumed the answer should be no for all these questions, but I may be learning something new...
edit
From the answers, I see its a Linux symlink. I guess that this means it is not portable to Windows, and would also make it more difficult to read outside a unix environment. I would also imagine that using relative paths (or include directories) instead of symlinks would be a better practice in cases like this for reasons mentioned above...
src/pacman/ini.h is a symbolic link according to the site.
Symbolic link has an information of where the target file is (path name), and I guess it is what is displayed on the site.
The OS will redirect access to that ini.h to ../common/ini.h, which is a normal C code.
I don't see any reason why not. The include statement indicates the compiler to replace that line with the whatever is in the included file
I'm looking at the legacy C project which relies on GNU Autotools. The existing M4 script (incorrectly) checks for FreeType headers like this:
AC_CHECK_HEADERS(freetype.h)
which is not the way FreeType should be included. The right way is:
#include <ft2build.h>
#include FT_FREETYPE_H
How do I require that all headers are included in the test program, not either of them?
To check for multiple headers depending on each other, you can use AC_COMPILE_IFELSE
Also if you google for "freetype m4" you will find several macros how to detect freetype.
The source codes downloaded from internet has a lot of non standard, uncommon header files
from a different depended modules, say.
#include<calendar.h>
or
#include <vconf.h>
Given any header file, is there a way to find out from which files these headers are fetched from?
look at the documentation of the lib to that the header belongs may the best way.
you also may look into the header and note down some function names and search through the lib which does define the symbol that belongs to that function
edit:
ah i thought you have a bunch of libs and headers and you do not know which you have to link to get functionality that is declared in a specific header
In your case looking at documentation from downloaded source code may be the only way (mostly this information is in the INSTALL or README - file)
No, not in general.
The string inside of #include is just a filename, and those can easily be reused by different projects, especially generic names like "calendar.h".
You could try googling the header names, or try to compile and google the function names that are used in the downloaded code, but defined in the missing header file. You could try asking the author of the code, or looking for more information from where you downloaded the code.