0

I'm tying to write a makefile, that should compile (and link) my program. For my program I have to use a bigger Libray with many .h and .cpp files, which comes in a specified filestructure(many other subdirectories)(I'm not allowed to change that stucture) My main.cpp is included in the first directory which also includes the makefile. This.cpp file includes headers out of the bigger library. And here comes the problem, when i try to "make" the terminal says:" fatal error: .. .h: File or Directory not found" #include ".. .h"

BTW: I'm using Ubuntu 18.04.1 with Gcc and gnu-make

Sooo... I tried several things the last 5 days. I tried to do it with a dependfile like this:

SRC = datei1.c datei2.c datei3.c datei4.c datei5.c
CC  = /usr/bin/gcc
DEPENDFILE = .depend

dep: $(SRC)
        $(CC) -MM $(SRC) > $(DEPENDFILE)

-include $(DEPENDFILE)

(Not sure if i made it the right way)

I was thinking of just including every single header file with include, but that would be waaay to much!

I guess the most powerful and useful thing till now was this URL: Makefile: How to correctly include header file and its directory?. That nearly described perfectly my problem, but it was just useful to include one single header file and not the whole library.

I guess it could be helpful to know how to correctly include a library. (Maybe try some ways over the PATH?)

Folder Sructure:

myproj
  |
  |____Makefile
  |____main.cpp
  |____init.cpp
  |____end.cpp
  |____init.h
  |____end.h
  |____Dependencies
           |____biggerlib
                   |____src   
                   |____include
                           |____biggerLib1
                           |____biggerLib2
                           |____biggerLib
                                   |____biggerLibrary.h
                                   |____Lib2.h
                                   |____Lib3.h
                                   |____AnotherDirWithFiles1
                                   |____AnotherDirWithFiles2
                                   |____AnotherDirWithFiles3
                                                |____etc.


#include in file:

#include "biggerLib/biggerLibrary.h"

I really do'nt know what to do anymore!

#Compiler directory
CC = gcc
#directories
SDCC = /home/myname/myproj/Dependencies/biggerlib/src
SDCH = /home/myname/myproj/Dependencies/biggerlib/include/biggerLib # normally ere are a few files and more directories!

#Dependenfile
#DEPENDFILE = .depend

#dep: $(SDCC)
#   $(CPP) -MM $(SDCC) > $(DEPENDFILE)

#-include $(DEPENDFILE)

#C-Flags for object-compiling
CFLAGS = -c -I$(SDCH)/..  #ugly!

#Deps including every single one? too much work!
#DEPS = $(SDCH)/biggerlibfile.h
#Libs for Compiler
#LIBS = -lSDCH

#Loading object list
include objects.mk

#Main-target (linking)
$(NAME) : $(OBJECTS)
    $(CC) -o $(NAME) #$+ $(LIBS)

#Object-targets
%.o : %.cpp #$(DEPENDFILE) #$(DEPS)
    $(CC) -o $@ $< $(CFLAGS)

Edit:

The single header file is working, but how do i include all the other header files in the even deeper directories? do I really need to include them all the same way? I need to include every Header behind "include".

I hope u guys understand my problem!:) Looking forward to your suggestions and tips!

  • I'm sorry i editet my stuff. But i honestly cant post my complete code – Kai Schoening Sep 05 '19 at 09:58
  • It is unclear what the current problem is. Assuming you are using the makefile in the last code block, does it produce the error message relating to the line `#include "biggerLib/biggerLibrary.h"`? If not, what error does it generate and on what source code line? – walnut Sep 05 '19 at 10:57
  • As I already stated in my now-deleted answer, if the whole of `biggerlib` is one third-party library, then you are probably expected to install it in some fashion. From the structure you posted, it seems like you simply copied the source code into your dependencies folder. If that is not the case, the library should at least document which directories need to be included with `-I`. – walnut Sep 05 '19 at 11:26
  • Yes you are right! but they just provide it for cmake. You gotta know, i build this lib with the help of cmake but now i need to include it in another bigger project with the help of make – Kai Schoening Sep 05 '19 at 11:45
  • This is not how it usually works. You install the library first on the target system and then install your own project afterwards. Both steps can use different build systems. This is usually handled by a package manager on the target system. – walnut Sep 05 '19 at 11:48
  • Okei thank you, that brings a little bit more light in the dark! But even more questions :D – Kai Schoening Sep 05 '19 at 11:52
  • do you have any helpful posts/ sites ec that could help me figure out how to do so? – Kai Schoening Sep 05 '19 at 11:54
  • The library should document what you need to do to install it, how to properly include its header files and what arguments need to be given to the compiler (which you then add to your make file). Everyone using your project must then follow the same installation steps as well. Also check whether the library does exist in your operating system repositories. If it does, installation is usually much easier through the package manager. The details are going to vary depending on how the library is written. – walnut Sep 05 '19 at 11:59
  • Thank you very much! I found a description (not a very good one, but t wokd out) – Kai Schoening Sep 05 '19 at 14:11

0 Answers0