Trouble linking with extern
I have these files
Code:
//simgroup.h
#include <vector>
#include "simCmd.h"
vector<simCmd*> *cmdList1;
//driver.C
#include <vector>
extern vector<simCmd*> *cmdList1;
//Make command
INCLUDE = -I/usr/include
LIBRARYPATH = -L/usr/lib -L/usr/X11R6/lib/
LIBRARIES = $(LIBRARYPATH) -lGL -lGLU -lglut -lm -lXi -lXmu -lpthread
CC = g++
CFLAGS = -O2 $(INCLUDE)
SRCS = simGroup.C simCmd.C driver.C
OBJS = $(SRCS:.C=.o)
EXE = simStart
all: $(EXE)
clean:
rm -rf core *~ *.o $(EXE)
$(EXE): $(OBJS) $(JLLIBS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LIBRARIES) $(FORMS_LIBS)
.C.o:
$(CC) $(CFLAGS) $< -c -o $@
//error when calling make
g++ -O2 -I/usr/include driver.C -c -o driver.o
driver.C:12: syntax error before `*' token
make: *** [driver.o] Error 1
Line 12 is the "extern vector<simCmd*> *cmdList1;"
If I add this to driver.C #include "simgroup.C", it compiles driver.o but problem happens when linking . Error is..
Code:
g++ -O2 -I/usr/include driver.C -c -o driver.o
g++ -O2 -I/usr/include -o simStart simGroup.o simCmd.o driver.o -L/usr/lib -L/usr/X11R6/lib/ -lGL -lGLU -lglut -lm -lXi -lXmu -lpthread
driver.o(.text+0x52): In function `main':
: undefined reference to `cmdList1'
collect2: ld returned 1 exit status
make: *** [simStart] Error 1
I'm not too familiar with makefiles and this seems like a valid attempt of using extern to make cmdList1 a global variable.