• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1472
  • Last Modified:

Compiler error: multiple definition of `gnu_dev_makedev'

I'm trying to port my app (a function library) over to Oracle Linux. It's a bunch of .c files which are compiled into a bunch of .o files, then I have a small test program which calls into one of the routines. But I get a ton of errors of the form:

multiple definition of `gnu_dev_makedev'

also for `gnu_dev_minor' and `gnu_dev_major'

over and over for functions in many of my .c files. Then it ends with

ld returned 1 exit status

I'm getting spotty info on this online and no good solutions. it sounds like this is some builtin function or macro multiply defined, though I also don't see why it's not a warning instead of an error. I've tried this with cc and gcc and there's no apparent difference.

My compile line for the .o is:

cc -c mycfile.c -I$TOPS -fPIC -shared

(TOPS is where my files are)
 
and for the main program is:

cc testctd.c *.o -lm
 
0
rich_tanenbaum
Asked:
rich_tanenbaum
  • 6
  • 4
1 Solution
 
Duncan RoeSoftware DeveloperCommented:
It would likely help if you could post some examples.
But in the meantime I  can see one thing - you have -l and -c options used together. That may be all the multiple definition problem is.
You should have:
gcc -c mycfile.c -fPIC
...
gcc -o mylib.so *.o -l$TOPS -shared

Open in new window

0
 
Duncan RoeSoftware DeveloperCommented:
i.e. separate commands to compile source to object and to build the final product.
-shared is only relevant if you want to build a shred library, so I assumed you wanted to do that.
ELF (i.e. normal) programs are shared anyway - if you run multiple instances
0
 
rich_tanenbaumAuthor Commented:
The font that was used obscures what I typed.

My compile line does have a -c which means "only compile, don't link" and what looks like an "l as in Larry" is really "I as in Idaho" to tell it where to find include files. So your gcc example line has no include in it, but i need tohave the include directory on the gcc compile line.

When you ask if I could post some examples, what are you looking for? Source code? gnu_dev_major etc. never appears in my source/
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Duncan RoeSoftware DeveloperCommented:
You still don't need -shared - that is a loader directive interpreted by gcc. Put the -I (eye) back by all means.
Post a sample c file that gives the errors and enough headers so it will compile (with errors) submit them using the File link below the Comment box - may be a tar or tgz or whatever EE allows
0
 
rich_tanenbaumAuthor Commented:
I think I discovered a workaround. I add -std=c99 to the compile command lines and I no longer get the error.

My test program now runs and gives an answer. But I'm curcious about what you're saying about -shared. My compile line in mymakefile is:

      gcc -c $(TOPS)/toppmain.c -I$(TOPS) -fPIC -shared -std=c99

where $TOPS is the direcotry with .c and .h files

and the main program build line is:

gcc testctd.c -o teststd.out *.o -lm

from a terminal prompt. So I have not created a libxxx.so. The thing that makes me think I'm doing something wrong is that when I change something in a .c file and recompile to a .o file, I need to also rebuild the test program for it to take effect, even though the concept of a shared library would make that unnecessary. Do i need to do something along the lines of

      ld -o libtops.so -dy $(OFILES) $(LIB)

(this is from my makefile when I compiled for Sun about 15 years ago). And then something for the main program build?
 
0
 
Duncan RoeSoftware DeveloperCommented:
Well done!
In your Makefile, alter the CFLAGS line to include this, or if you don't have one put:

CFLAGS = -std=c99

I think for sure -shared is unnecessary, even if it does no harm.
It sounds to me as though the dependencies in your Makefile are not right. Really, you have to list all the .o files or do something smart if you are sure your program depends on all .o files - I'm thinking of something like in the box (which should get you going, by the way - it's from the Makefile for my editor).
Sun and GNU Makefiles both have smart capabilities but they are in general incompatibly so I'm guessing your still-working Makefile didn't use any.
# Extract from a Makefile I actually use (program name changed to myprog)

SRCS = $(wildcard *.c)
OBJ = $(SRCS:.c=.o)
myprog : $(OBJ)

# The lines below at the end of your Makefile will take care of dependencies automatically -
# any time you change a .h file (in $TOPS), all the appropriate files will be re-compiled

%.d: %.c
        $(CC) -MM -MT $(@:.d=.o) -MT $@ $(CPPFLAGS) $< > $@
-include $(SRCS:.c=.d)

# real tab char before $(CC)

Open in new window

0
 
Duncan RoeSoftware DeveloperCommented:
You only need to build a shared library if you have more than one program that will use it. Use gcc rather than ld - gcc will include the necessary system (and gcc) libraries. It would look a bit like:
gcc -o libtops.so -shared *.o

Open in new window

0
 
rich_tanenbaumAuthor Commented:
Here is what finally worked for me:

in makefle, one line per c file:

      gcc -c $(TOPS)/toppmain.c -I$(TOPS) -fPIC -shared -std=c99

where TOPS is set as an environment variable to be the path to the directory with the c files.

Then from a terminal, while in the $TOPS directory,

gcc -shared -o libtops.so *.o

to make the .so file, and

gcc testctd.c -o testctd.out -lm $TOPS/libtops.so

to build the test app.

One remianing issue is that i thought sometime during the day I needed to build with -lc along with -lm because of problems linking in calls to the stat function, but at the end of the day it workeed without it, so I',m not sure if it's necessary for my particular code base.
0
 
Duncan RoeSoftware DeveloperCommented:
You get -lc automatically when you load with gcc (but not with ld)
0
 
rich_tanenbaumAuthor Commented:
I'd give higher grades but I found out the solution to my immediate problem elsewhere.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now