Thread: Makefiles, Object files, Source files, OH MY!

  1. #1

    Makefiles, Object files, Source files, OH MY!

    Hmm... My third qhestion of the night.

    I am trying to make my program lake less time to compile, so i made my program modular (.o files), and made a makefile to only compile what is needed.

    Here is the deal (greatly simplified):
    main.cpp
    Code:
    #include "file2.h"
    #include "file3.h"
    #include "file4.h"
    file2.cpp
    Code:
    #include "file2.h"
    class stuff;
    file3.cpp
    Code:
    #include "file3.h"
    class morejunk;
    file4.cpp
    Code:
    #include "file4.h"
    class evenmorejunk;
    And all the .h files hold the prototypes for their namesake.cpp files.
    Now, the makefile has this: (simplified, again)

    makefile
    Code:
    junk : main.o file2.o file3.o file4.o
            g++ -o junk main.o file2.o file2.o file4.o
    
    file2.o : file2.cpp file2.h
            g++ -c file2.cpp
    
    file3.o : file3.cpp file3.h
            g++ -c file3.cpp
    
    file4.o : file4.cpp file4.h
            g++ -c file4.cpp
    Now, the linker is giving me errors telling me:
    Code:
    nemoserv.cpp:27: storage size of `log' isn't known
    nemoserv.cpp:30: storage size of `opts' isn't known
    nemoserv.cpp:49: storage size of `chman' isn't known
    nemoserv.cpp:50: storage size of `cmd' isn't known
    These are the elements of a struct that is defined in a separate source file, and
    Code:
    nemoserv.cpp:277: aggregate `rawMsg message' has incomplete type and 
    cannot be initialized
    This class is defined also in another source file.

    Please tell me what I am doing wrong, or if you need more information (and what)

    Thanks!
    ~EtherealFlaim
    [/CODE]
    Last edited by Inquirer; 04-29-2003 at 09:40 PM.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Those are compiler errors, not linker errors. You will need to post nemoserv.cpp (and any files it includes) if you want it fixed for you.
    Also, if you've made any changes, re-post the compiler errors so the line numbers will correct.

    gg

  3. #3
    Code:
    g++ -ggdb -pthread -c nemoserv.cpp
    nemoserv.cpp:27: aggregate `logger log' has incomplete type and cannot 
    be initialized
    nemoserv.cpp:30: aggregate `parsedArgs opts' has incomplete type and 
    cannot be initialized
    nemoserv.cpp:49: aggregate `chanManager chman' has incomplete type and 
    cannot be initialized
    nemoserv.cpp:50: aggregate `commander cmd' has incomplete type and 
    cannot be initialized
    nemoserv.cpp: In function `int main (int, char **)':
    nemoserv.cpp:88: invalid use of undefined type `struct parsedArgs'
    nemoirc.h:20: forward declaration of `struct parsedArgs'
    nemoserv.cpp: In function `int recvParser (char *, int)':
    nemoserv.cpp:277: aggregate `rawMsg message' has incomplete type and 
    cannot be initialized
    nemoserv.cpp: At top level:
    nemoserv.cpp:27: storage size of `log' isn't known
    nemoserv.cpp:30: storage size of `opts' isn't known
    nemoserv.cpp:49: storage size of `chman' isn't known
    nemoserv.cpp:50: storage size of `cmd' isn't known
    make: *** [nemoserv.o] Error 1
    Thats the full make output. It works (compiles, not like perfectly) if you uncomment the line in the two .h files (that have .cpp namesakes) and just compile the main module.

    (NOTE: THIS FILE IS MADE WITH `tar -czvf all.zip *`, so you will need tar to unzip it. I'm not sure what graphical unzippers can untar/gunzip files. You may have to rename the file to .tgz or .tar.gz)
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to create a C project with multiple source files
    By MSF1981 in forum C Programming
    Replies: 5
    Last Post: 03-22-2009, 09:25 AM
  2. Multiple Source Files, make files, scope, include
    By thetinman in forum C++ Programming
    Replies: 13
    Last Post: 11-05-2008, 11:37 PM
  3. Conditional compilation for object files in Makefile?
    By jutirain in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2007, 06:23 AM
  4. Threads to keep the CPU faster than the disk?
    By matthew180 in forum C Programming
    Replies: 4
    Last Post: 06-06-2007, 03:23 PM
  5. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM