public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Help in Makefiles for multiple file application
@ 2004-07-23  8:06 Giri Raja
  2004-07-23  8:21 ` sandeep
  0 siblings, 1 reply; 2+ messages in thread
From: Giri Raja @ 2004-07-23  8:06 UTC (permalink / raw)
  To: ecos-discuss

Hi,
   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;
void init();

extern "C"  {
        void cyg_user_start();
}

#endif

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

one.cc

#include "ll.h"

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

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

init.cc

include "ll.h"

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

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




	
		
__________________________________
Do you Yahoo!?
Vote for the stars of Yahoo!'s next ad campaign!
http://advision.webevents.yahoo.com/yahoo/votelifeengine/

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ECOS] Help in Makefiles for multiple file application
  2004-07-23  8:06 [ECOS] Help in Makefiles for multiple file application Giri Raja
@ 2004-07-23  8:21 ` sandeep
  0 siblings, 0 replies; 2+ messages in thread
From: sandeep @ 2004-07-23  8:21 UTC (permalink / raw)
  To: Giri Raja; +Cc: ecos-discuss

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-07-23  6:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-23  8:06 [ECOS] Help in Makefiles for multiple file application Giri Raja
2004-07-23  8:21 ` sandeep

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).