[MERFISH Error] Error3:fatal error: ‘fftw3.h’ file not found \#include

Continue generating storm_ There are new errors in various dynamic libraries required by analysis this time.

fatal error: 'fftw3.h' file not found 
------->#include <fftw3.h>

A header file is missing. So install it yourselffftw this library is the fast Fourier transform Library of C language.

Official installation guide installing fftw on MacOS

Step 1. Install the C language fftw Library

Later, baidu found that homebrew can install this directly, so type the command brew install fftw, and part of the output of the installation process is as follows

==> ./configure --prefix=/usr/local/Cellar/open-mpi/4.0.2 --enable-ipv6 --with-libevent=/usr/local/opt/libevent --with-sge
==> make all
==> make check
==> make install
🍺  /usr/local/Cellar/open-mpi/4.0.2: 752 files, 11.2MB, built in 12 minutes 57 seconds
==> Installing fftw
==> ./configure --enable-single --enable-shared --prefix=/usr/local/Cellar/fftw/3.3.8_1 --enable-threads --enable-mpi --enable-openmp -
==> make install
==> make clean
==> ./configure --enable-shared --prefix=/usr/local/Cellar/fftw/3.3.8_1 --enable-threads --enable-mpi --enable-openmp --enable-sse2 --e
==> make install
==> make clean
==> ./configure --enable-long-double --enable-shared --prefix=/usr/local/Cellar/fftw/3.3.8_1 --enable-threads --enable-mpi --enable-ope
==> make install
🍺  /usr/local/Cellar/fftw/3.3.8_1: 73 files, 14.8MB, built in 6 minutes 56 seconds
==> Caveats
==> hwloc
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

After installation, you can find a series of header files under the default path /usr/local/include of GCC. You can see the time. I just installed it

ll /usr/local/include | grep fftw
lrwxr-xr-x    1 user  admin      44 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3-mpi.f03
lrwxr-xr-x    1 user   admin      42 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3-mpi.h
lrwxr-xr-x    1 user   admin      38 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3.f
lrwxr-xr-x    1 user   admin      40 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3.f03
lrwxr-xr-x    1 user   admin      38 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3.h
lrwxr-xr-x    1 user   admin      45 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3l-mpi.f03
lrwxr-xr-x    1 user  admin      41 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3l.f03
lrwxr-xr-x    1 user  admin      41 Aug 12 09:53 [email protected] -> ../Cellar/fftw/3.3.8_1/include/fftw3q.f03

As for how to determine the /usr/local/include, you can use the following command to view the default library file search path of GCC

 gcc -x c -v -E /dev/null
 
 ##Partial output display with default include addressing path
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/11.0.3/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "/dev/null"

Step 2. Solve the problem that the header file cannot be associated with the source file

After the header file is installed and can be found, regenerate the dynamic link library. This time, you will not be prompted that the header file cannot be found, but the previous error appears again.

gcc  -dynamiclib -o libmatched_filter.dylib matched_filter.c
Undefined symbols for architecture x86_64:
  "_fftw_destroy_plan", referenced from:
      _cleanup in matched_filter-d9e7cc.o
  "_fftw_execute", referenced from:
      _convolve in matched_filter-d9e7cc.o
      _initialize in matched_filter-d9e7cc.o
  "_fftw_free", referenced from:
      _cleanup in matched_filter-d9e7cc.o
  "_fftw_malloc", referenced from:
      _initialize in matched_filter-d9e7cc.o
  "_fftw_plan_dft_c2r_2d", referenced from:
      _initialize in matched_filter-d9e7cc.o
  "_fftw_plan_dft_r2c_2d", referenced from:
      _initialize in matched_filter-d9e7cc.o
  "_ftmComplexCopyNormalize", referenced from:
      _initialize in matched_filter-d9e7cc.o
  "_ftmComplexMultiply", referenced from:
      _convolve in matched_filter-d9e7cc.o
  "_ftmDoubleCopy", referenced from:
      _convolve in matched_filter-d9e7cc.o
      _convolveMemo in matched_filter-d9e7cc.o
      _initialize in matched_filter-d9e7cc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This time I understand that the header file must be found, but the source file corresponding to the header file cannot be associated. Because it is installed with homebrew, the installation path may not be in the default addressing path of GCC. So yesterday’s error report about kdtree cannot be solved. It must be the same reason.

The association between C language header file and library function is queried on the network, and the following information is obtained.

2. How do header files relate to source files

This problem actually means that the header file “A.H” declares a series of functions, which are implemented in “b.cpp”. If I want to use the functions declared in “A.H” and implemented in “b.cpp” in “c.cpp”, I usually use #include “A.H” in “c.cpp”, then how can c.cpp find the implementation in b.cpp?

In fact, there is no direct relationship between. CPP and. H file names. Many compilers can accept other extensions. For example, I now see the source code of our company, and the. Cpp file is replaced by the. CC file.

In Turbo C, it is compiled in the command line mode. The command line parameters are the name of the file. The default are. CPP and. H, but it can also be customized to. XXX and so on.

In Mr. Tan Haoqiang’s book c programming, it is mentioned that during compiler preprocessing, the #include command should be “file included”: copy all the contents of File2. C to #include “File2. C”. This explains why many compilers don’t care what the suffix of this file is — because #include preprocessing is to complete the work of “copy and insert code”.

When compiling, you won’t find the function implementation in the b.cpp file. You can only do this when link. Using #include “A.H” in b.cpp or c.cpp actually introduces relevant declarations so that the compilation can pass. The program does not care where or how the implementation is. The source file is compiled into an object file (. O or. Obj file). In the object file, these functions and variables are regarded as symbols. In link, you need to specify which. O or. Obj file to connect in the makefile (here, the. O or. Obj file generated by b.cpp). At this time, the connector will go to the. O or. Obj file to find the functions implemented in b.cpp, and then build them into the executable file specified in the makefile.

Reference link: association between C header file and source file

So my link process will make mistakes, because the linker can’t find where the original file is. Naturally, it can’t be used in the declared function in the header file.

Using - L and - L to specify the path, there are still errors, but at least some errors are found, and there are many fewer undefined files.

gcc -L /usr/local/lib -l fftw3  -dynamiclib -o libmatched_filter.dylib matched_filter.c
Undefined symbols for architecture x86_64:
  "_ftmComplexCopyNormalize", referenced from:
      _initialize in matched_filter-9f6f25.o
  "_ftmComplexMultiply", referenced from:
      _convolve in matched_filter-9f6f25.o
  "_ftmDoubleCopy", referenced from:
      _convolve in matched_filter-9f6f25.o
      _convolveMemo in matched_filter-9f6f25.o
      _initialize in matched_filter-9f6f25.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation

# Explain the parameters
-L # the path where the dynamic library is located
-l #Take the name of the dynamic library. If the dynamic library file is libxxxx.dylib, you should enter -l when setting the parameter. xxxx

Undefined content of this error message

Something about GCC’s link parameters: GCC – L – L – I

Similar Posts: