0

I'm trying to run make on an Ubuntu machine to compile a RoT MUD, but the farthest I've gotten is when I get a collect2: error: ld returned 1 exit status.

This is what comes immediately before the error in the terminal (along with a lot of other similar errors):

/usr/bin/ld: obj/wizlist.o:/home/lucas/Projects/R2b5/src/merc.h:3355: multiple definition of `bllmax'; obj/act_comm.o:/home/lucas/Projects/R2b5/src/merc.h:3355: first defined here

From what I've gathered this means that the header files have variable declarations in them, and that using static is an easy fix, however, I haven't been able to figure out where I should put that keyword in the code to fix this issue. The following is the only mention of bllmax in merc.h:

int bllmax, crbmax, crnmax, srpmax, mngmax;

Here is the program I'm trying to compile.

1 Answers1

0

You need to learn the difference between declaration and definition. A declaration is telling the compiler that the symbol exists somewhere but possibly not here. A definition is telling the compiler that the symbol exists here.

The line you show (without any context) is defining the variables, which means they will be defined in each source file that includes the header file.

What it should do is to declare the variables, which can be done by making them extern:

extern int bllmax, crbmax, crnmax, srpmax, mngmax;

Then in a single source file define the variables (without extern).

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • Thank you, I got "declaration" and "definition" mixed up, but that still doesn't answer my question. This is old code which was once able to be compiled, so I don't understand why making these definitions `extern` would be necessary. Not only that, but there are about a hundred other definitions in the program, so would I have to add `extern` to each one and then create a source file for them? Also, what other context would you like for the line I provided? It's in a header file called merc.h and defines a variable that is in the error I put in my question. – Lucas Aquino de Assis Jul 17 '21 at 16:37
  • @LucasAquinodeAssis It was a long time since I looked through any MERC based source, but isn't there some kind of conditional compilation (`#ifdef` or similar) which puts the definitions in only a single source file? Also note that even if a code-base is publicly and legally available, that doesn't mean it's actually good or even buildable from the get-go. Especially considering that most of them were written a *very* long time ago when compilers might not have been as strict as they are today. – Some programmer dude Jul 17 '21 at 17:03
  • @LucasAquinodeAssis I've checked the code now, and this is indeed a problem. The only reason this ever worked was probably because the compilers and linkers back then were much more lax. These multiple definitions isn't the only errors, I couldn't even get to the linking stage when attempting to build. If you want to build it you have a lot of work ahead of you. – Some programmer dude Jul 21 '21 at 15:57