Linking required header file during make - makefile

I am trying to make a sample binary against a project that I've already compiled.
The compilation fails with
$ make
c++ -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
tileinfo.cpp:7:10: fatal error: 'vector_tile_compression.hpp' file not found
#include "vector_tile_compression.hpp"
^
1 error generated.
make: *** [tileinfo] Error 1
I can see the missing header file in the project source. I want to include it at compilation time, so that it can be found. I assume simply copying all the source is incorrect & that I should be able to point to this header file. I tried the -I flag, but no matter what path I give it, it still fails to find this header file.
So I cave in and copy the header file...
$ cp ../../src/vector_tile_compression.hpp .
$ make
c++ -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
./vector_tile_compression.hpp:5:10: fatal error: 'vector_tile_config.hpp' file not found
#include "vector_tile_config.hpp"
^
1 error generated.
make: *** [tileinfo] Error 1
OK, it's after a new file now and it's just going to want more and more. Let's move the entire project source into the example...
$ cp ../../src/* .
$ make
c++ -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: fatal error: 'protozero/types.hpp' file not found
#include <protozero/types.hpp>
^
1 error generated.
make: *** [tileinfo] Error 1
Well that looks a bit like progress (though I'm worried I took a wrong turn). It wants protozero. It's included in a subfolder of the project called deps. Ok, I try to include that.
$ make -I ../../deps/protozero/include/
c++ -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: fatal error: 'protozero/types.hpp' file not found
#include <protozero/types.hpp>
^
1 error generated.
make: *** [tileinfo] Error 1
Again, I tried a few variations on the path, but this -I flag, I think it does not do what I think it does.
So in desperation I copy the dependency.
$ cp -r ../../deps/protozero/include/protozero .
$ make
c++ -D_THREAD_SAFE -I/usr/local/Cellar/protobuf/2.6.1/include -L/usr/local/Cellar/protobuf/2.6.1/lib -lprotobuf-lite tileinfo.cpp ../../src/vector_tile.pb.cc -o tileinfo -lprotobuf-lite -lz
In file included from tileinfo.cpp:7:
In file included from ./vector_tile_compression.hpp:5:
./vector_tile_config.hpp:10:10: error: 'protozero/types.hpp' file not found with <angled> include; use "quotes" instead
#include <protozero/types.hpp>
^~~~~~~~~~~~~~~~~~~~~
"protozero/types.hpp"
And this message tells me I shouldn't copy the files, but link to them instead. Clearly I'm on the wrong track. What should I be doing instead?

You are almost there. I'll recap the steps in a cleaner way (even if you already got some done).
First you need to download the dependency. Looking at mapnik-vector-tile project Makefile we have:
PROTOZERO_REVISION=v1.3.0 git clone https://github.com/mapbox/protozero.git ./deps/protozero && cd ./deps/protozero && git checkout $(PROTOZERO_REVISION)
After running this command from the root folder of your project you'll have a deps folder with protozero inside.
Finally, you have to tell the compiler about this new include path by appending
-I./deps/protozero/include
to the CXXFLAGS of your Makefile (supposing that you use a structure for your file similar to the one inside the binary link you provided).

Related

Writing a MakeFile for a C compiler, getting a "no input files" fatal error

my MakeFile is like this: (this creates a main program that takes a file and produces syntax trees, TAC code etc. Classes used in main.cpp and the parser.y are defined in classes.cpp)
MAIN = main
PARSE = parser
SCAN = scanner
CLASS = classes
compiler: lex.yy.c y.yab.h y.tab.c $(CLASSES).cpp
g++ -std=c++11 -Wno-write-strings -o compiler $(MAIN).cpp
y.tab.c y.tab.h: $(PARSE).y $(CLASSES).cpp
yacc -d $(PARSE).y
lex.yy.c: $(SCAN).l
lex $(SCAN).l
clean:
rm -f lex.yy.* y.tab.* *.tokens *.syntree *.tac *.log compiler
but when I run make I get
g++ -o .cpp
g++: fatal error: no input files
compilation terminated.
<builtin>: recipe for target '.cpp' failed
make: *** [.cpp] Error 1
how do I resolve this?
“error: no input files” means src files were not exist. Common reason is you move or remove some src file.

fatal error: png.h: No such file or directory(MiddleBury Evaluation)

I am testing stereo algorithm in MiddleBury Stereo Evaluation
One of step was to compile the tools in code/as follows.
cd code/imageLib
make
cd ..
make
cd ..
In this case, there is error in first make as follows,
$ make
g++ -O3 -W -Wall -g -c -o ImageIOpng.o ImageIOpng.cpp
ImageIOpng.cpp:19:17: fatal error: png.h: No such file or directory
compilation terminated.
make: *** [<builtin>: ImageIOpng.o] Error 1
and, regarding second make,
$ make
g++ -g -O3 -W -Wall -IimageLib ii.cpp -LimageLib -lImg.i686-g -lpng -lz -o ii
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lImg.i686-g
/usr/lib/gcc/i686-pc-cygwin/5.4.0/../../../../i686-pc-cygwin/bin/ld: cannot find -lpng
collect2: error: ld returned 1 exit status
make: *** [<builtin>: ii] Error 1
In previous step, make worked fine.
So, what was the problem? I downloaded sample algorithm and did not edit/change contents in any file.
png.h is part of libpng16-devel and the specific include
directory must be added to the include path of your project.
$ cygcheck -l libpng16-devel |grep png.h
/usr/include/libpng16/png.h

gfortran makefile 'can't open included file'

I'm having an issue with a makefile compiling and I'm not sure where to start diagnosing this. It was generated for a colleague's OS X system, and I'm trying to implement it on my linux system. It worked on the OS X computer. I've updated library locations to represent where they live on my computer - and this is likely the biggest source of error, as gfortran procedure shouldn't be different, no?
The included files: file0.i, ... fileN.i all live in the same directory as the makefile.
I'm certain if I could compile the first object file I could get through the rest and complete my PhD or save the world or something.
A snippet of the file follows:
# %W% %G%
# Makefile for directory ~/Documents/workstuff/project/program
#
fflags = -O3 -I. -I/usr/local/include -frecord-marker=4 -ffree-form
## -fdefault-real-8 -fdefault-double-8
lflags = -L/usr/local/lib -lnetcdf -lnetcdff
# for debugging, use these options
fflags = -g
lflags = -g
chem = ~/Documents/workstuff/project/chem
main.o: $(chem)/code/main.f file0.i file1.i file2.i
gfortran -c $(fflags) $(chem)/code/main.f
And I receive the following error:
~/Documents/workstuff/project/program/chem/code/main.f:11: Error: Can't open included file 'file0.i'
makefile:14: recipe for target 'main.o' failed
make: *** [main.o] Error 1
I thought it might be an executable issue, so we went from 644 to 744:
username$ file file0.i
file0.i: ASCII text
username$ stat -c '%A %a %n' file0.i
-rwxr--r-- 744 file0.i
Still same error. Double-check that my flags are pointing to the right place:
username$ nf-config --fflags
-I/usr/local/include
username$ nf-config --flibs
-L/usr/local/lib -lnetcdff -lnetcdf -lnetcdf
For what its worth, file0.i contains the following, which I have of course filled with nonsense numbers for sharing online:
$Id: file0.i,v 1.12 2012/12/31 04:25:23 username Exp $
PARAMETER (NLT=19,NHT=51,DZETA=0.5/3.,Psurf=100.)
PARAMETER (NLT1=NLT+1,NHT1=NHT+2,NLT2=3*NLT+1,NHT2=4*NHT+1)
PARAMETER (NDYEAR=33,NTN=75,NTCV=14,NLV=21,NPOL=8,NGSP=3)
PARAMETER (NDIST=111,TD1=110.,NVC=1,NVSP=1,NVTIME=3)
Does anything obvious stick out to anyone?
I do not know gfortran very well, so I may be completely wrong, but for gcc, if a C source file contains:
#include <foo.h>
and if gcc is called with -I., foo.h will be searched in the same directory as the source file, not in the directory where you call gcc from. Example:
$ ls foo
bar.c bar.h
$ cat foo/bar.c
#include <bar.h>
int main(int argc, char **argv) {
return 0;
}
$ gcc -I. foo/bar.c
foo/bar.c:1:10: error: 'bar.h' file not found with <angled> include; use "quotes" instead
#include <bar.h>
^~~~~~~
"bar.h"
1 error generated.
$ gcc -Ifoo foo/bar.c
$
So, it could be that you should put your header files in the same directory as your source file or use a -I<path> where <path> is the absolute path of where you call gfortran from.

gcc: fatal error: no input files

I am trying to compile some source code but I presented with the following error output after entering "make":
mpicc -c -O3 -I func_pointer.c
gcc: fatal error: no input files
compilation terminated.
make: *** [func_pointer.o] Error 4
I have seen other threads on this website relating to this error output (1, 2, 3). I was in fact experiencing a similar problem previously, which I think I may have solved, where the "make" command was producing:
make: Circular mod_prec.o <- mod_prec.o dependency dropped.
make: Circular mod_prec.o <- mod_prec.o dependency dropped.
make: Circular mod_prec.o <- mod_prec.o dependency dropped.
/usr/bin/cpp -P -C -traditional -DIFORT -P -C -traditional -DWET_DRY -DMULTIPROCESSOR -DLIMITED_NO -DGCN mod_prec.F > mod_prec.f90
mpif90 -c -O3 -I mod_prec.f90
gfortran: fatal error: no input files
compilation terminated.
make: *** [mod_prec.o] Error 4
I followed the steps suggested on this website, which I think may have addressed that issue (I believe I am progressing further through the makefile). Those steps are as follows:
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ which mpif90
/usr/local/bin/mpif90
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ mpif90 -show
gfortran -I/usr/local/include -pthread -I/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -L/usr/local/lib -lmpi_usempi -lmpi_mpifh -lmpi
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ mpif90 -V
gfortran: error: unrecognized command line option ‘-V’
gfortran: fatal error: no input files
compilation terminated.
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ export MPI_LOC=/usr/local
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ export MPI_INCLUDE="$MPI_LOC"/includedan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ export MPI_LIB="$MPI_LOC"/lib
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ export LD_LIBRARY_PATH=$MPI_LIB:$LD_LIBRARY_PATH
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ export LIBMPI="-pthread -Wl -rpath -Wl -Wl,--enable-new-dtags -lmpi -lmpi_usempi -lmpi_mpifh -lmpi"
With an additional step of:
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ make clean
/bin/rm -f *.o *.mod *.f90
Which brought me to where I am currently. My instinct is that the solution to my current problem will be similar to that of my previous problem. However, I am new to linux/c/fortran so I am not sure I fully follow the previous solution. As such the following commands produce the following output:
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ which mpicc
/usr/local/bin/mpicc
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ mpicc -show
gcc -I/usr/local/include -pthread -Wl,-rpath -Wl,/usr/local/lib -Wl,--enable-new-dtags -L/usr/local/lib -lmpi
dan#Dan-office ~/FVCOM3.2.2/FVCOM_source $ mpicc -V
gcc: error: unrecognized command line option ‘-V’
gcc: fatal error: no input files
compilation terminated.
Have I failed to correctly define some variables which is leading to this problem? I am conscious that this question is becoming rather long but I can add additional information if it is required such as the makefile (this is long though).
Answering my own question after encountering it again whilst compiling FVCOM on a new hard drive. The issue is, as raised by Etan, the -I flag. In the make.inc file uncomment the LIBDIR and INCDIR variables under local install and comment out the same variables directly above.

make library not found

I'm trying to compile a program using a third party library, Omnet++ in my case. Apparently "make" does not find a library, but the path it uses is correct as you can see (in the sense that I can see the library under omnet++ source tree)
pv135168:basic Bob$ opp_makemake
Creating Makefile in /Users/Bob/Code/network_sim/basic... Makefile created, running "make depend" to add dependencies... opp_makedep -Y --objdirtree -I. -f Makefile -P\$O/ -- ./*.cc
pv135168:basic Bob$ make
g++ -c -g -Wall
-fno-stack-protector -m32 -DHAVE_PCAP -DXMLPARSER=libxml
-DWITH_PARSIM -DWITH_NETBUILDER -I.
-I/Users/Bob/Code/omnetpp-4.1/include -o out/gcc-debug//txc1.o txc1.cc g++ -m32 -Wl,-rpath,/Users/Bob/Code/omnetpp-4.1/lib -Wl,-rpath,. -o out/gcc-debug//basic out/gcc-debug//txc1.o -Wl,-all_load
-L"/Users/Bob/Code/omnetpp-4.1/lib/gcc"
-L"/Users/Bob/Code/omnetpp-4.1/lib" -u _tkenv_lib -lopptkenvd
-loppenvird -lopplayoutd -u _cmdenv_lib -loppcmdenvd -loppenvird
-loppsimd -lstdc++
ld: library not found for -lopptkenvd
collect2: ld returned 1 exit status make: *** [out/gcc-debug//basic]
Error 1 pv135168:basic Bob$
It's looking in the following directories for a file called libopptkenvd.dylib or libopptkenvd.a:
/Users/Bob/Code/omnetpp-4.1/lib/gcc
/Users/Bob/Code/omnetpp-4.1/lib
Is that file in one of those directories (or in the standard directories like /usr/lib)? I don't see an indication of that in your output.

Resources