This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Help in Makefiles for multiple file application


Please see the comments inline.

I'm getting a weird problem. I have wrote 2 sample
c++ files with a common header that is included for
both the files. When I try to make it, I get multiple
definition errors for the data structures used. I do
have the #define directive in my header file. The
weird part is that the whole thing properly compiles
if the applications are c files. I'm giving below the Makefile and the c++ files that I
used. Can someone please point me in the right
direction. Thank you.


Giri.

*************************************************

Makefile

INSTALL_DIR=$$(INSTALL_DIR) # override on make command
line

include $(INSTALL_DIR)/include/pkgconf/ecos.mak

XCC           = $(ECOS_COMMAND_PREFIX)gcc
XCXX          = $(XCC)
XLD           = $(XCC)
CFLAGS        = -g -Wall -mcpu=arm7tdmi
-I$(INSTALL_DIR)/include
CXXFLAGS      = $(CFLAGS)
LDFLAGS       = -nostartfiles -L$(INSTALL_DIR)/lib
-Ttarget.ld
OBJ = init.o

#RULES

all: one

init.o: init.cc ll.h
        $(XCC) $(LDFLAGS) $(CFLAGS) -c init.cc

one: one.cc $(OBJ) ll.h
        $(XCC) $(LDFLAGS) $(CFLAGS) -o one one.cc
$(OBJ)


***************************************


header file

#ifndef JJ
#define JJ

// common header files
#include <pkgconf/system.h>
#include <pkgconf/kernel.h>
#include <pkgconf/libc.h>
#include <pkgconf/hal.h>
#include <cyg/infra/cyg_type.h>
#include <cyg/kernel/kapi.h>
#include <cyg/hal/hal_arch.h>
#include <cyg/hal/hal_io.h>
#include <cyg/hal/var_io.h>
#include <cyg/hal/plf_io.h>
#include <cyg/io/io_diag.h>
#include <pkgconf/io_serial.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>

int i;
int c;
// change these to
extern int i;
extern int c;
// and define them in one of the files.
// header files should be containing declarations, not definitions.
void init();

extern "C"  {
        void cyg_user_start();
}

#endif

**************************************

one.cc

int i;
#include "ll.h"

void cyg_user_start(void)  {
        init();
        for(;;)  {
                i++;
        }
}

********************************************

init.cc

int c;
include "ll.h"

void init()  {
        for(;;)  {
                c = 100;
        }
}

********************************************

it works with C compiler (when both are .c files), because *-gcc by default take 'common' model. if you add "-fno-common" to your CFLAGS, you will get the same problem of multiple definitions even when you try your experiment with above as C files.

HTH
sandeep
--------------------------------------------------------------------------
Q:  How many IBM cpu's does it take to do a logical right shift?
A:  33.  1 to hold the bits and 32 to push the register.
--------------------------------------------------------------------------


-- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]