[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

C vs. C++ problem



Hej, 

jeg har prøvet at konvertere nogle programmer fra C til C++, men
enkelte ting giver mig grå hår (og jeg er kun 23). Problemet kan skæres
ned til følgende:
Jeg har en del variable jeg ikke gider kaste rundt imellem
funktionerne, og derfor vil jeg have dem globale. Desuden vil jeg have
delt funktionerne ud på flere filer, og så er det problemerne opstår.
Linkeren kommer med beskeder om at de variable allerede er defineret,
her er et eksempel og det virker fint i C, men ikke i C++? 
 
// filen globals.h :
#ifndef GLOBALS_H
#define GLOBALS_H

#include <stdio.h>

void Testfunk();
int a, b, c[100];

#endif


// filen main.cpp :
#include "globals.h"

int main(void)
{
  Testfunk();
  return(0);
}

// filen Cppfil2.cpp :
#include "globals.h"

void Testfunk()
{
  printf("made it!\n");
  return;	
}


// Makefile:
CC = g++
CFLAGS = -O3 -fmemoize-lookups

PROGNAME = test.x

SOURCES = main.cpp \
	Cppfil2.cpp \

OBJECTS = $(SOURCES:.cpp=.o)

.cpp.o:
	$(CC) -c $(CFLAGS) $< -o $@

$(PROGNAME): $(OBJECTS)
	$(CC) $(OBJECTS) -o $(PROGNAME) 

clean:
	rm -f $(PROGNAME)
	rm -f *.o
	rm -f *~


Er det et problem med Makefilen, for det styrer jeg ikke rigtigt. 
Det er som om #ifndef ikke virker i C++??

Sune
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:07 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *