Hi,
Thanks for the reply guys.
I have made the changes that you suggested but I am still getting same error when I run make. I am attaching the code as text files to this reply. I did not write inputMap.cc..it was given to us as part of our project source.
I need some help understanding stuff that you guys have suggested.
First,
You are using the implicit rule for compiling .cc files into .o files. I'm a bit rusty on the syntax, but assuming you have that set up correctly, you don't need an explicit command to compile inputMap.c. What you have now has two problems: (1) you are saying that the file inputMap depends on the file inputMap,which doesn't make sense, and (2) the command is going to try to build an executable called inputMap from inputMap.o, which won't work because there is no main function in inputMap.c. Try removing those two lines completely.
I am assuming that implicit rule means basically since I need inputMap.o for project and I have inputMap.cc in the directory, make will automatically find it and compile it. Is that correct?
Second,
Rather make a LDFLAGS variable that uses the -l option to link the shared library properly. (This is probably the reason for the errors you got when linking)
What are LDFLAGS? I have not worked with makefiles before, so this is pretty new to me. I have googled for tutorials but they dont explain the meaning of the flags.
Third,
As mentioned before, the inputMap target is unnecessary, and the project target needs to be changed to use the LDFLAGS instead of LIBS:
I made that change..but I have no idea what that means. Could someone please explain that to me.
Finally, here are my current makefile and header.h:
Code:
CC=g++
LDFLAGS=-lplayerc++
CFLAGS=-g -Wall -I/usr/include/player-2.0
EXECUTABLES=project
all: $(EXECUTABLES)
clean:
rm -f core $(EXECUTABLES) *.o
.SUFFIXES: .cc .o
.cc.o:
$(CC) $(CFLAGS) -c -o $@ $<
project: project.o inputMap.o
$(CC) $(LDFLAGS) -o $@ project.o inputMap.o
Code:
#ifndef HEADER_H
#define HEADER_H
#include <libplayerc++/playerc++.h>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unistd.h>
#include <fstream>
#include <string>
#include </usr/share/player/examples/libplayerc++/args.h>
const double pi = M_PI;
using namespace PlayerCc;
using namespace std;
void inputMap(int output);
#endif
Here is the error I am getting right now:
Code:
g++ -g -Wall -I/usr/include/player-2.0 -c -o project.o project.cc
g++ -g -Wall -I/usr/include/player-2.0 -c -o inputMap.o inputMap.cc
g++ -lplayerc++ -o project project.o inputMap.o
inputMap.o:/usr/include/c++/4.2/bits/stl_algobase.h:182: multiple definition of `gHostname'
project.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2560: first defined here
inputMap.o: In function `print_usage(int, char**)':
/usr/share/player/examples/libplayerc++/args.h:59: multiple definition of `print_usage(int, char**)'
project.o:/usr/share/player/examples/libplayerc++/args.h:59: first defined here
inputMap.o: In function `parse_args(int, char**)':
/usr/share/player/examples/libplayerc++/args.h:15: multiple definition of `parse_args(int, char**)'
project.o:/usr/share/player/examples/libplayerc++/args.h:15: first defined here
inputMap.o:(.data+0x0): multiple definition of `gPort'
project.o:(.data+0x0): first defined here
inputMap.o:/usr/include/c++/4.2/bits/stl_algobase.h:182: multiple definition of `gIndex'
project.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2560: first defined here
inputMap.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2562: multiple definition of `gDebug'
project.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2562: first defined here
inputMap.o:(.data+0x4): multiple definition of `gFrequency'
project.o:(.data+0x4): first defined here
inputMap.o:(.data+0x8): multiple definition of `gDataMode'
project.o:(.data+0x8): first defined here
inputMap.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2562: multiple definition of `gUseLaser'
project.o:/usr/include/c++/4.2/bits/locale_facets.tcc:2562: first defined here
collect2: ld returned 1 exit status
make: *** [project] Error 1
Thanks.
Bookmarks