www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - Another link question: how to allow re-definitions?

↑ ↓ ← "Luna Kid" <lunakid neuropolis.org> writes:
Can optlink allow linking a working executable, when
modules have conflicting definitions -- symbols having
the same name but associated with non-identical code,
resolved by e.g. some "first/last wins" logic, like
some other linkers do?

(Remember "poor man's polymorphism", e.g. for overriding
default callback functions provided by a library...)

Cheers,
Lunatic Sz.
May 12 2003
↑ ↓ "Walter" <walter digitalmars.com> writes:
"Luna Kid" <lunakid neuropolis.org> wrote in message
news:b9p93i$30pi$1 digitaldaemon.com...
 Can optlink allow linking a working executable, when
 modules have conflicting definitions -- symbols having
 the same name but associated with non-identical code,
 resolved by e.g. some "first/last wins" logic, like
 some other linkers do?

I'm sorry, it does not. I don't know of any linker that has that.
 (Remember "poor man's polymorphism", e.g. for overriding
 default callback functions provided by a library...)

You must be thinking of how libraries are searched for unresolved symbols, in order. That works.
May 12 2003
↑ ↓ "Luna Kid" <lunakid neuropolis.org> writes:
 modules have conflicting definitions -- symbols having
 the same name but associated with non-identical code,
 resolved by e.g. some "first/last wins" logic, like
 some other linkers do?

I'm sorry, it does not. I don't know of any linker that has that.

LCCLNK was the last one I used this way. See below, please.
 (Remember "poor man's polymorphism", e.g. for overriding
 default callback functions provided by a library...)

You must be thinking of how libraries are searched for unresolved symbols, in order. That works.

Yes, that's part of the game. The question is how the duplicate definitions can be resolved in a scenario like this: FRAMEWORK.LIB: _main _callback_one ; default implementation _callback_two ; default implementation ... MYAPP.OBJ: _callback_one ; custom implementation So, how to correclty link this stuff with OPTLINK? link myapp.obj, myapp.exe,, framework.lib, app.def, app.res does not seem to be enough. I used to manage with the few compiler systems I tried, but that was some 5 years ago. But I know LCC works, for sure, as just tried it again: lcclnk -subsystem windows -o test.exe test.obj winmill.lib test.res Of course, I get warnings: def_app.obj: multiple definition of _wm_configure first definition is in file test.obj def_app.obj: multiple definition of _wm_pre_loop first definition is in file test.obj def_app.obj: multiple definition of _wm_post_loop first definition is in file test.obj Time: 8.982 seconds But the executable is created perfectly OK. Thanks, Sz.
May 13 2003
"Luna Kid" <lunakid neuropolis.org> writes:
Some more info...

windowed.def:
    EXETYPE NT
    SUBSYSTEM WINDOWS


link /nodel main.obj test.obj, test.exe,, winmill.lib gdi32.lib,
    windowed.def, test.res

OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

winmill.lib(def_app)  Offset 04702H Record Type 0091
 Error 1: Previous Definition Different : _wm_configure
winmill.lib(def_app)  Offset 04714H Record Type 0091
 Error 1: Previous Definition Different : _wm_pre_loop
winmill.lib(def_app)  Offset 04727H Record Type 0091
 Error 1: Previous Definition Different : _wm_post_loop

--- errorlevel 3

P:\win32_\WinMill\lib\v0.05-dmc>test.exe

...

So, the EXE is there. But it does not run: (see the attached box).

Now, is it possible that OPTLINK has already been doing
it for me, I just screw up the EXE type somehow? Or is
this failure indeed due to an incomplete link?

Thanks,
Sz.
May 13 2003
↑ ↓ → "Luna Kid" <lunakid neuropolis.org> writes:
 So, the EXE is there. But it does not run: (see the attached box).

Dammit, sorry! (FAR Manager appends a space to the filename on copy, that's why it won't open... :-/ ) Spammer Sz.
May 13 2003
→ "Walter" <walter digitalmars.com> writes:
You can try what's called a "weak" extern.

"Luna Kid" <lunakid neuropolis.org> wrote in message
news:b9qhmq$14o3$1 digitaldaemon.com...
 modules have conflicting definitions -- symbols having
 the same name but associated with non-identical code,
 resolved by e.g. some "first/last wins" logic, like
 some other linkers do?

I'm sorry, it does not. I don't know of any linker that has that.

LCCLNK was the last one I used this way. See below, please.
 (Remember "poor man's polymorphism", e.g. for overriding
 default callback functions provided by a library...)

You must be thinking of how libraries are searched for unresolved


 in order. That works.

Yes, that's part of the game. The question is how the duplicate definitions can be resolved in a scenario like this: FRAMEWORK.LIB: _main _callback_one ; default implementation _callback_two ; default implementation ... MYAPP.OBJ: _callback_one ; custom implementation So, how to correclty link this stuff with OPTLINK? link myapp.obj, myapp.exe,, framework.lib, app.def, app.res does not seem to be enough. I used to manage with the few compiler systems I tried, but that was some 5 years ago. But I know LCC works, for sure, as just tried it again: lcclnk -subsystem windows -o test.exe test.obj winmill.lib test.res Of course, I get warnings: def_app.obj: multiple definition of _wm_configure first definition is in file test.obj def_app.obj: multiple definition of _wm_pre_loop first definition is in file test.obj def_app.obj: multiple definition of _wm_post_loop first definition is in file test.obj Time: 8.982 seconds But the executable is created perfectly OK. Thanks, Sz.

May 13 2003
→ "Walter" <walter digitalmars.com> writes:
Also, put your "default implementations" each in a separate .obj file, and
put those .obj files in a library. Link that library last.

"Luna Kid" <lunakid neuropolis.org> wrote in message
news:b9qhmq$14o3$1 digitaldaemon.com...
 modules have conflicting definitions -- symbols having
 the same name but associated with non-identical code,
 resolved by e.g. some "first/last wins" logic, like
 some other linkers do?

I'm sorry, it does not. I don't know of any linker that has that.

LCCLNK was the last one I used this way. See below, please.
 (Remember "poor man's polymorphism", e.g. for overriding
 default callback functions provided by a library...)

You must be thinking of how libraries are searched for unresolved


 in order. That works.

Yes, that's part of the game. The question is how the duplicate definitions can be resolved in a scenario like this: FRAMEWORK.LIB: _main _callback_one ; default implementation _callback_two ; default implementation ... MYAPP.OBJ: _callback_one ; custom implementation So, how to correclty link this stuff with OPTLINK? link myapp.obj, myapp.exe,, framework.lib, app.def, app.res does not seem to be enough. I used to manage with the few compiler systems I tried, but that was some 5 years ago. But I know LCC works, for sure, as just tried it again: lcclnk -subsystem windows -o test.exe test.obj winmill.lib test.res Of course, I get warnings: def_app.obj: multiple definition of _wm_configure first definition is in file test.obj def_app.obj: multiple definition of _wm_pre_loop first definition is in file test.obj def_app.obj: multiple definition of _wm_post_loop first definition is in file test.obj Time: 8.982 seconds But the executable is created perfectly OK. Thanks, Sz.

May 13 2003