uniting all .h files in an include folder

This is a discussion on uniting all .h files in an include folder within the C++ Programming forums, part of the General Programming Boards category; Hi guys I have the following makefile, where I am building a library out of some code that used to ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    52

    uniting all .h files in an include folder

    Hi guys

    I have the following makefile, where I am building a library out of some code that used to build 3 unit tests. The problem is, if I want to use it as a library I will need the Header files with which to compile my application. I just want to know what statement I could put, so that all header files that are used to build the library, are copied into an include folder, I don't know if they need to keep the same file structure inside this include folder.

    Thanks in advance,
    Ed.

    Code:
    CXX=g++
    CC=gcc
    
    CXXFLAGS=-gstabs -I../../.. -Wall -D_REENTRANT
    LDFLAGS=-lpthread
    
    OBJ_DIR=.
    BIN_DIR=.
    
    THREAD_SRC=linux_thread.cc
    SHARE_SRC=../../minidump_file_writer.cc\
    	  ../../../common/string_conversion.cc\
    	  ../../../common/linux/file_id.cc\
    	  minidump_generator.cc
    HANDLER_SRC=exception_handler.cc\
    	    ../../../common/linux/guid_creator.cc
    SHARE_C_SRC=../../../common/convert_UTF.c
    
    THREAD_TEST_SRC=linux_thread_test.cc
    MINIDUMP_TEST_SRC=minidump_test.cc
    EXCEPTION_TEST_SRC=exception_handler_test.cc
    
    THREAD_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o,$(THREAD_SRC))
    SHARE_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o,$(SHARE_SRC))
    HANDLER_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o,$(HANDLER_SRC))
    SHARE_C_OBJ=$(patsubst %.c,$(OBJ_DIR)/%.o,$(SHARE_C_SRC)) md5.o
    THREAD_TEST_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o, $(THREAD_TEST_SRC))\
    		$(THREAD_OBJ)
    MINIDUMP_TEST_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o, $(MINIDUMP_TEST_SRC))\
    		  $(THREAD_OBJ) $(SHARE_OBJ) $(SHARE_C_OBJ)
    EXCEPTION_TEST_OBJ=$(patsubst %.cc,$(OBJ_DIR)/%.o, $(EXCEPTION_TEST_SRC))\
    		   $(THREAD_OBJ) $(SHARE_OBJ) $(SHARE_C_OBJ) $(HANDLER_OBJ)
    
    BIN=$(BIN_DIR)/minidump_test\
        $(BIN_DIR)/linux_thread_test\
        $(BIN_DIR)/exception_handler_test
    
    BIN=$(BIN_DIR)/libexception_handler.a
    
    LIB_OBJS= $(THREAD_OBJ) $(SHARE_OBJ) $(HANDLER_OBJ) $(SHARE_C_OBJ)
    
    .PHONY:all clean
    
    all:$(BIN)
    
    $(BIN): $(LIB_OBJS)
    	ar rcs $(BIN) $(LIB_OBJS)
    
    #$(BIN_DIR)/linux_thread_test:$(THREAD_TEST_OBJ)
    #	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@
    
    #$(BIN_DIR)/minidump_test:$(MINIDUMP_TEST_OBJ)
    #	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@
    
    #$(BIN_DIR)/exception_handler_test:$(EXCEPTION_TEST_OBJ)
    #	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@
    
    
    # Rule for object files
    %.o: %.cc
    	$(CXX) $(CXXFLAGS) -c $<
    
    md5.o:../../../common/md5.c
    	$(CC) $(CXXFLAGS) -c $^
    
    clean:
    	rm -f $(BIN) *.o *.dmp

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    What statement you could put where, exactly?

    I guess if you really mean that you're making a library, then your header files should be in the include path (/usr/local/include or whatever it is). But that would happen at install/copy time, not compile time.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    52
    What I mean, is that I know that the makefile will use a bunch of header files that come from different subdirectories.. and I find it annoying to build the library and do a trial and error search for this files, so that I can copy them and make an include with all of them in it.

    You see, the makefile at first was meant for building unit-tests.. and I am modifying it so that all the object files used in those unit tests are archived in a single library that I can use with my own application.


    Thanks,

    Ed.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, wait. You're compiling three C++ files, right? You can't look at the source of those three files and see what .h files they use (or have grep look at the source for you)? Or are these somebody else's headers? I'm confused.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    most compilers already put all the .h files in a single directory. Your project should as well. If you mean it shoudl put all your custom .h files from yoru projects in with all teh other .h files that are part of the compiler, then trust that is a bad idea. What if you accidentalyl write a custom math.h, ir woudl overwrite the base package math.h and break yoru other projects.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Registered User
    Join Date
    Jul 2008
    Posts
    52
    most compilers already put all the .h files in a single directory. Your project should as well. If you mean it shoudl put all your custom .h files from yoru projects in with all teh other .h files that are part of the compiler, then trust that is a bad idea. What if you accidentalyl write a custom math.h, ir woudl overwrite the base package math.h and break yoru other projects.
    No.. but they are not in the same directory... that's what is painful about this project.. the header files are all in different subdirectories, it just looks for them there.

    Well, wait. You're compiling three C++ files, right? You can't look at the source of those three files and see what .h files they use (or have grep look at the source for you)? Or are these somebody else's headers? I'm confused.
    Well, I mean it was compiling 3 programs but , I'm trying to use those 3 programs's objects.. and compile them in a single library. So my output is a libexception_handler.a
    but I need to obtain all the headers that were used to create this libexception_handler.a

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by afflictedd2 View Post


    Well, I mean it was compiling 3 programs but , I'm trying to use those 3 programs's objects.. and compile them in a single library. So my output is a libexception_handler.a
    but I need to obtain all the headers that were used to create this libexception_handler.a
    So if you have .o files, you don't need .h files (unless you're compiling extra code with those object files). If the .o files come from elsewhere, and you are supposed to be using them with your own code, then the .h files should come with; if people are giving you .o files without the corresponding .h files, then you need to hit them with a hammer until they stop. If you are making your .o files from .cc files, then the .cc files tell you what .h files you will need to compile them (probably -- some of the .h files may include other .h files).

    On the other hand, reading your makefile, I don't see where you are using anybody else's .o files, except md5.o.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    find . -name "*.h" -print|xargs cp {} ./include
    perhaps? [I may have this slightly wrong].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jul 2008
    Posts
    52
    If people are giving you .o files without the corresponding .h files.
    It is kind of like what you're saying there. I am producing a bunch of object files but I don't know which header files it's using to make those object files. And I need to know! because if I want to use that library I need to be able to specify those headers.

    They specify in the makefile
    Code:
     -I../../../
    so it is including whatever headers are 3 levels up hmmm, and well what I notice in some of the code is that for example this is from exception_handler.h

    Code:
    #include "client/linux/handler/minidump_generator.h"
    If I put all of this headers that are spread out in a single folder, will I have to change this to
    Code:
    #include "minidump_generator.h"
    Last edited by afflictedd2; 11-26-2008 at 12:48 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-14-2005, 01:21 PM
  2. .h files: "constant already defined"
    By wakeup in forum C++ Programming
    Replies: 11
    Last Post: 11-22-2005, 04:31 AM
  3. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM
  4. Code to display files and sizes of any folder
    By CrackDown in forum Linux Programming
    Replies: 0
    Last Post: 04-22-2003, 11:23 AM
  5. opengl .h files
    By Unregistered in forum Game Programming
    Replies: 3
    Last Post: 10-18-2001, 08:32 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21