Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Compiler error: multiple definition of `gnu_dev_makedev'

Posted on 2010-11-08
10
Medium Priority
?
1,358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 35

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 35

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

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 35

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 35

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 35

Accepted Solution

by:
Duncan Roe earned 1500 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. http://www.linuxmint.com. Once you open the link you will see …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Suggested Courses

715 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