Solved

Compiler error: multiple definition of `gnu_dev_makedev'

Posted on 2010-11-08
10
1,305 Views
Last Modified: 2012-05-10
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
Comment
Question by:rich_tanenbaum
  • 6
  • 4
10 Comments
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 34091050
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 34091061
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
 

Author Comment

by:rich_tanenbaum
ID: 34093731
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 34

Expert Comment

by:Duncan Roe
ID: 34096470
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
 

Author Comment

by:rich_tanenbaum
ID: 34096755
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 34100141
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 34100366
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
 

Author Comment

by:rich_tanenbaum
ID: 34102475
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
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 34106107
You get -lc automatically when you load with gcc (but not with ld)
0
 

Author Closing Comment

by:rich_tanenbaum
ID: 34106201
I'd give higher grades but I found out the solution to my immediate problem elsewhere.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question