Header files for fftw missing? - c

I installed a new system and all of the libraries on to it. However, I have problems with fftw. After cmake command I get the following error
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:138 (message):
Could NOT find FFTW (missing: FFTW_LIBRARIES FFTW_INCLUDES)
I can find where the FFTW libraries are (/usr/lib64/), but I can't find where header files for fftw are located. How can I find them? Also, for some other header files: is it safe to put a symbolic link in /usr/includes/ instead of giving the full path in .c code?

You can use the Unix command locate to determine the location of the FFTW header files
$ locate fftw3.h
/usr/local/include/fftw3.h
If you install FFTW 3 from source the header file fftw3.h should be placed in /usr/local/include/ by default.
The FFTW header files for FFTW 2 are contained in the package fftw-dev and for FFTW 3 are contained in the package libfftw3-dev.
The /usr/local directory is intended to contain all the user binaries, their documentation, libraries, header files, etc.... so it is ok to symlink library files in there, providing you do it correctly.

Related

How to install C source files and headers?

I've been given these source files and headers. In the README.md the authors explain how to launch the test executables without the need of a proper installation. It is just a make command to run. They explain how to generate the .so files. I think these latter are meant to be used if I wanted to install the APIs at a system level (the definitions should be in api.h). My question is: where should I copy the shared objects generated by the Makefile and the api.h header? I aim to write a source file from scratch where I use those APIs (e.g. crypto_sign()) just including the headers, if it is possible. Thanks
where should I copy the shared objects generated by the Makefile and the api.h header? I aim to write a source file from scratch where I use those APIs (e.g. crypto_sign()) just including the headers, if it is possible
Nowhere.
The project comes with CMake support. Use CMake in your project and just add_subdirectory the repository directory.
Anyway, if you really wish to install the library system-wide, then FHS specifies directory structure on linux. For local system administration use /usr/local/lib for local libraries .so files and /usr/local/include for local C header files.

Using gcc for compiling/converting, matrix.h: No such file or directory

I'm trying to convert some .c files to R files using gcc.
The files im talking about are circulant.c and circulant.h files located at:
http://www.columbia.edu/~ad3217/fbm.html
There the author also provided short instructions how to do it with gcc.
Things I did so far:
installed Ubuntu via the Win10 Linux Subsystem
installed build essentials
installed gcc
downloaded all meschach files from
http://www.netlib.org/c/meschach/
putting the meschach folder and circulant.x files into one folder and running the command
$gcc -I meschach/ -c circulant.c
gives the error:
In file included from circulant.c:25:0:
circulant.h:11:20: fatal error: matrix.h: No such file or directory
compilation terminated.
I hope that someone with more knowledge with gcc can help me out and point me to a solution.
You aren't using the right header files.
You have some dependency issues you need to take care of first. From the comment header block of circulant.c:
/* This program simulates fractional Gaussian noise or fractional */
/* Brownian motion using the Wood and Chan algorithm. */
/* The C-packages Ranlib and Meschach are used, both available */
/* via Netlib (http://www.netlib.org). */
Looks to me like the missing matrix.h and matrix2.h files are from the meschach library.
You can't just copy the .shar files into a directory.
You need to read the README file and follow the installation instructions. So I would recommend installing the ranlib and meschach dependencies first.

Including libraries in the custom code section in Simulink

I'm trying to Include some Libraries, like metis in the custom code library section in Simulink. Do you know what type of libraries Simulink excepts? Must they have the ending .a, .o, .dll or lib?
And can I include them into my custom c code with #include <metis.h>?
The library format should match the architecture on which you are going to compile the generated code. So .a or .so for GNU/Linux, .lib for Windows (you usually link against the .lib file not the .dll), and usually .dylib on Mac. You can also link in object files, (i.e. .o, .obj) but typically a software package will build some type of library for you to use.
If you are using any of the functions, types, etc. defined in any of the metis headers, then those headers need to be included in the generated code.
You can add #include "header_name.h" to the settings:
"Configuration Parameters->Simulation Target->Custom Code->Header File"
and:
"Configuration Parameters->Code Generation->Custom Code->Header File"
where header_name.h is replaced with the needed header file's name.
Since this question is tagged MATLAB Coder you can also use coder.cinclude('header_name.h'); in your MATLAB code to generate a #include "header_name.h" in the C code.
You may also need to augment the Include directories settings on the aforementioned Custom Code panes to allow the compiler to locate the headers.

GNU C compiler cannot locate header file

I have installed a package libstree on my machine (x86_64/Redhat Linux).
Have followed the instructions ( ./configure --prefix=/usr; make check; make install) to install the package.
Have checked that the relevant header files are in the /usr/include and /usr/lib directories.
However when I try to compile a test program I get an error message:
test.c:6:25: fatal error: lst_structs.h: No such file or directory
compilation terminated.
lst_structs.h is present in the /usr/include/stree directory.
Anyone have any thoughts as to why the GNU C compiler cannot locate the header file?
As it's in an /include sub-directory, you need to explicitly mention it (see comments above), or adjust your lib include path, as outlined on this old stackoverflow post:
How to add a default include path for gcc in linux?

How do you actually use a C library?

I'm sure this question has been asked many times, but I can't figure this out. Bear with me.
So when you download a library, you get a bunch of .c and .h files, plus a lot of other stuff. Now say you want to write a program using this library.
I copy all the .h files into my project directory. It just doesn't compile.
Great, so then I get the library as a bunch of .dll's, and i copy the dlls into my project directory. Still doesn't compile.
How does this work?
What do you do, like right after creating the folder for your project? What parts of the library package do you copy/paste into the folder? How do you make it so that it can compile? Go through the steps with me please.
Where to put the .h files?
Where to put the .dll files?
How to compile?
Thanks.
(the library I'm trying to get working is libpng, I'm in windows with MinGW, and i'm looking to compile from command-line like usual.)
(from what i gather, you put the .h files in directory A and the .dll files in directory B and you can use -l and -L compiler options to tell the compiler where to find them, is this correct?)
Here's a brief guide to what happens when you compile and build a basic C project:
The first stage compiles all your source files - this takes the source files you've written and translates them into what are called object files. At this stage the compiler needs to know the declaration of all functions you use in your code, even in external libraries, so you need to use #include to include the header files of whatever libraries you use. This also means that you need to tell the compiler the location of those header files. With GCC you can use the -I command line to feed in directories to be searched for header files.
The next stage is to link all the object files together into one executable. At this stage the linker needs to resolve the calls to external libraries. This means you need the library in object form. Most libraries will give you instructions on how to generate this or might supply it ready built. Under Linux the library file is often a .a or .so file, though it might just be a .o. Again you can feed the location of the library's object file to GCC with the -L option.
Thus your command line would look like this:
gcc myProg.c -I/path/to/libpng/include -L/path/to/libpng/lib -lpng -o myProg.exe
(Note that when using the -l command line GCC automatically adds lib to the start of the library, so -lpng causes libpng.a to be linked in.)
Hope that helps.
Doing it under windows (supposing you user Visual Studio)
After unpacking add the library include directories to your projects' settings (Project -> Properties -> C/C++ -> Additional Include Directories)
Do the same thing for the Libraries Directory (Project -> Properties -> Linker -> Additional Library Directories)
Specify the name of the library in your Linker Input: Project -> Properties -> Linker -> Input -> Additional Dependencies
After this hopefully should compile.
I don't recommend adding the directories above to the Global settings in Visual Studio (Tools -> Options -> Project and Solutions) since it will create and environment where something compiles on your computer and does NOT compile on another one.
Now, the hard way, doing it for a Makefile based build system:
Unpack your stuff
Specify the include directory under the -I g++ flag
Specify the Library directory under the -L g++ flag
Specify the libraries to use like: -llibrary name (for example: -lxml2 for libxml2.so)
Specify the static libraries like: library name.a
at the end you should have a command which is ugly and looks like:
g++ -I/work/my_library/include -L/work/my_library/lib -lmylib my_static.a -o appname_exe MYFILE.CPP
(the line above is not really tested just a general idea)
I recommend go, grab a template makefile from somewhere and add in all your stuff.
You must link against a .lib or something equivalent i.e. add the ".lib" to the libraries read by the linker. At least that's how it works under Linux... haven't done Windows so a long while.
The ".lib" contains symbols to data/functions inside the .dll shared library.
It depends on the library. For examples, some libraries contain precompiled binaries (e.g. dlls) and others you need to compile them yourself. You'd better see the library's documentation.
Basically, to compile you should:
(1) have the library's include (.h) file location in the compiler's include path,
(2) have the library stubs (.lib) location in the linker's library path, and have the linker reference the relevant library file.
In order to run the program you need to have the shared libraries (dlls) where the loader can see them, for example in your system32 directory.
There are two kinds of libraries: static and dynamic (or shared.)
Static libraries come in an object format and you link them directly into your application.
Shared or dynamic libraries reside in a seperate file (.dll or .so) which must be present at the time your application is run. They also come with object files you must link against your application, but in this case they contain nothing more than stubs that find and call the runtime binary (the .dll or the .so).
In either case, you must have some header files containing the signatures (declarations) of the library functions, else your code won't compile.
Some 'libraries' are header-only and you need do nothing more than include them. Some consist of header and source files. In that case you should compile and link the sources against your application just as you would do with a source file you wrote.
When you compile, assuming you have the libs and the headers in the same folder as the sources you are compiling, you need to add to your compile line -L . -I . -lpng. -L tells the linker where to look for the library, -I tells the compiler where to look for the headers and -lpng tells the linker to link with the png library.
[Edit]
Normal projects would have some sort of hierarchy where the headers are in an /include folder and the 3rd party libs are in a /libs folder. In this case, you'd put -I ./include and -L ./libs instead of -I . and -L.
[Edit2] Most projects make use of makefile in order to compile from the command line. You can only compile manually for a small number of files, it gets quite hectic after that
Also,
you may want to look over Dynamic Loading support in various languages and on various
platforms.
This support is very handy in cases when you want to use a library optionally and you don't want your program to fail in case that library is not available.

Resources