1

I'm working on a project that has the line: #include <fftw3.h>

Now I can simply download and make fftw. But how do I make it a 'global' library?

I have tried adding it to $PKG_CONFIG_PATH but this doesn't seem to work. I'm constantly ending up with this error: main.c:30:10: fatal error: 'fftw3.h' file not found

So my question is: where do I need to make the fftw library (or any library for that matter) to make it globally accessible?

note: I might use the term global incorrectly, in that case, please let me know what the correct term would be.

Update: The command is:

gcc -Wall -march=native -O3 -ffast-math `pkg-config --cflags fftw3` `pkg-config --cflags sndfile` -c -o main.o main.c

main.c contains the line

#include <fftw3.h>
jotik
  • 17,044
  • 13
  • 58
  • 123
Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101
  • 1
    What compiler are you using? You normally have a setting for the paths that it examines to find the files. Or try adding it to your Path environment variable. – Andrew Truckle May 24 '16 at 10:14
  • 3
    search for a package to install at the *system* level for your os, if you were on some linux distro, look for an appropriate package from the repo and then install that. That will drop in the headers and pre-built libraries in the right places.. – Nim May 24 '16 at 10:14
  • use `-I` compile switch ? – M.M May 24 '16 at 10:23
  • Possible duplicate of [What are the GCC default include directories?](http://stackoverflow.com/questions/4980819/what-are-the-gcc-default-include-directories) – Tamás Szelei May 24 '16 at 10:37
  • @TamásSzelei thanks for this link. But now I would like to learn how I can add the fftw lib to one of these directories... – Bob van Luijt May 24 '16 at 10:43
  • It may be a duplicate @TamásSzelei , but not a duplicate of that exact question – CoffeDeveloper May 24 '16 at 11:07
  • @BobvanLuijt copy it there? Not sure what you are after. There is no magic involved. The build system of the project in question might provide an install function which copies to these directories. – Tamás Szelei May 24 '16 at 11:19
  • @DarioOO I don't know what you mean by that. Is it a duplicate in your opinion or not? I fail to see any possible middle ground. Don't get me wrong, it's fine if you disagree with it being a duplicate. – Tamás Szelei May 24 '16 at 11:21
  • I was simply saying that I don't believe your question is technically a duplicate, however it suprise me no one already asked the same as OP (maybe there exist a duplicate wich I was not able to find). – CoffeDeveloper May 24 '16 at 12:00

2 Answers2

0

I don't think there is a precise answer the way you put it - there is no "global" library, because "fftw3.h"is a header file.

There are 3 things here: 1) Where you find header files 2) Where you find static (or stub/import) libraries 3) Where you find dynamic libraries (at runtime)

For 1), the answer is "depends on the configuration of your build tool". So is 2). For 3, it is usually "in the path, in the same folder as the executable, in the current directory, or in a platform specific directory". It would be slightly different for Windows, Linux, or another platform.

In short, you will need to configure your build tool for it.

EDIT: Now that we know what your tool is, I would suggest reading this short page explaining how GCC looks for headers (your .h file). You can either put your header file in one of the search paths (sloppy!, not recommended), or put your "extra" headers in a directory of your choosing and add it to the compilation command with the "-I" parameter.

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

Gerasimos R
  • 2,056
  • 1
  • 12
  • 22
  • 1
    Thanks, this is bringing me a bit closer. I have added the initial g++ command to my question. Do you mean I somehow need to set the path for ` --cflags fftw3`? – Bob van Luijt May 24 '16 at 10:34
  • Yes you need both to specify a path to header files, and a path to the static library, see my answer :) – CoffeDeveloper May 24 '16 at 12:01
0

beign able to include files using <file> is generally bad practise, it increase the risk of files with same name became ambiguos (especially on big projects).

You can achieve that by specifing additional global include directories using the -I compiler option. However there is no best way to achieve that (it depends on how project is organized and how it is big).

Include by absolute path:

#include <file>
#include <somepath/file2>

Pros:

  • Source code structure is more flexibile (you can move your files without warrying about breaking compilation)

Cons:

  • More chance of name clash between files

Include by path relative to source file:

#include "../file"
#include "../somepath2/file2"

Pros:

  • No chance for name clash, there exist only 1 file given any relative path

Cons:

  • You cannot move files around otherwise relative paths needs to be changed (however refactoring tools of your IDE may help with that)

Definitely I prefer using absolute path for standard library stuff and eventually FEW other dependencies, while otherwise I use only relative paths. You should note that when the compiler search for global include files, it will search in all provided -I directories, so if you abuse that feature it is likely you will increase compile time.

Of course even when using global includes, I prefer adding just 1 extra directory and organize that so that the compiler doesn't have to guess paths

Include
  +FolderNameSpace1
  +FolderNameSpace2

So I have just to add the namespace when including

#include <FolderNameSpace1/File1>

Some open source projects, had this problem in mind, however since not all people is willing to spend too much time organizing folder structure, their developers used the more simple strategy to prepend a suffix on Header file names (to avoid name clash).. In example in Ogre you have to do:

#include <OgreFileName>
//or (depending on how your project is organized)
#include "../Deps/OgreFileName"

So after some premise, to answer your question,

you have to add as "global include directory" the directory that has all include files you want to use, so Given you are using GCC and your project is organized like that:

Project
  +FFWT
    +includes
  +yourfolder
    +yoour files

you have just to do:

gcc -Wall -march=native -O3 -ffast-math -I../FFWT/includes c -o main.o main.c

(I am assuming you are calling GCC from inside "yourfolder")

How to add additional global include directories:

Community
  • 1
  • 1
CoffeDeveloper
  • 7,961
  • 3
  • 35
  • 69