Recent

Author Topic: [SOLVED] Multiple defined symbol form an obj file  (Read 2605 times)

Okoba

  • Hero Member
  • *****
  • Posts: 528
[SOLVED] Multiple defined symbol form an obj file
« on: August 16, 2021, 08:25:39 am »
Is there a way to find out a symbol is already defined, so I can prevent redefining it so the compiler don't give error like this?
Quote
Error: Multiple defined symbol "XXXXX"
« Last Edit: August 16, 2021, 02:35:16 pm by Okoba »

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: I have an obj file that
« Reply #1 on: August 16, 2021, 08:55:59 am »
Would you please describe your problem more clearly? From the cut of title of the thread and the error message I assume that you're trying to link some object file and you get errors when linking it, but that's not really clear. So please, provide more information.

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: I have an obj file that
« Reply #2 on: August 16, 2021, 09:04:59 am »
Sure.

I have an object file that I like to use in two units in two separate packages, Pkg1Unit and Pkg2Unit, both like to have that object and link it. The problem is that if I use both of these packages in a project, FPC gives the error that I am trying too link a symbol multiple times.
I can make a third package that use this object and those two packages use this, but it complicated things and I have no control on one of the packages to change the code. So I am looking for a way to find out if this symbol is defined or this object is linked, the I can prevent linking again or redefining it in my code.
I can change the source of pakcages but as I said, I have not much control on their source and I like to know if there is way for this particular problem without change in the dependency package.

I renamed the topic but it only renames the first post.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Multiple defined symbol form an obj file
« Reply #3 on: August 16, 2021, 09:16:04 am »
Is your object file in the same location relative to the two packages or does each package have its own copy? If the later then that simply won't work and your only solution is what you had suggested with a third unit/package. If the former I think the linker should catch that both files are the same and thus not complain, but I can't say that for sure.

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: Multiple defined symbol form an obj file
« Reply #4 on: August 16, 2021, 09:20:48 am »
You guessed right. They are in different location. Two packages with no knowledge of each other and usage of the same obj as dependency.
So it is a linker issue. There is no check or thing like Declared() that can know about if a function or object is declared somewhere else already? I know if the unit uses that unit, it is known, but I like to know about the whole project.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Multiple defined symbol form an obj file
« Reply #5 on: August 16, 2021, 01:28:54 pm »
You guessed right. They are in different location. Two packages with no knowledge of each other and usage of the same obj as dependency.

Then that simply does not work.

So it is a linker issue. There is no check or thing like Declared() that can know about if a function or object is declared somewhere else already? I know if the unit uses that unit, it is known, but I like to know about the whole project.

No. A unit has no way of knowing what another unit that it doesn't use itself might use. And there is especially no way of knowing for the pre-linking parts of the compiler what symbols an object file might provide.

Okoba

  • Hero Member
  • *****
  • Posts: 528
Re: Multiple defined symbol form an obj file
« Reply #6 on: August 16, 2021, 02:35:02 pm »
Thank you very much for the clarification.

 

TinyPortal © 2005-2018