www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - VC linker - unresolved external symbols - runtime

reply "deed" <none none.none> writes:
sc.ini
--------------------
[Environment]
DFLAGS="-I% P%\..\..\src\phobos" 
"-I% P%\..\..\src\druntime\import"
VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 
10.0\VC
WindowsSdkDir=C:\Program Files\Microsoft SDKs\Windows\v7.1
LIB="% P%\..\lib"

[Environment32]
LIB="% P%\..\lib"
LINKCMD=% P%\link.exe

[Environment64]
LIB="% P%\..\lib64";%WindowsSdkDir%\lib\x64
DFLAGS=%DFLAGS% -L/OPT:NOICF
LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe
VC2010 LINKCMD=%VCINSTALLDIR%\bin\amd64\link.exe
LIB=%LIB%;"%VCINSTALLDIR%\lib\amd64"
LIB=%LIB%;"%WindowsSdkDir%\Lib\win8\um\x64"
LIB=%LIB%;"%WindowsSdkDir%\Lib\x64"
-------------------


build
-------------------
-ofprog.exe
-m64

-L-subsystem:windows

./src/main.d
user32.lib
-------------------


main.d
-------------------
...
int WintMain(...)
{
     ...
     try
     {
         Runtime.initialize();
         ...
         Runtime.terminate();
     }
     ...
}
--------------------

$ dmd  build
error LNK2019: unresolved external symbol 
_D4core7runtime7runtime10initializeFZb referenced in function 
WinMain
error LNK2019: unresolved external symbol 
_D4core7runtime7Runtime9terminateFZb referenced in function 
WinMain

core.runtime's import path is specified in the sc.ini file, in 
DFLAGS
If I specify the core.runtime file in the build file everything 
works

Why is it so?
Nov 09 2013
parent reply "evilrat" <evilrat666 gmail.com> writes:
On Saturday, 9 November 2013 at 15:30:55 UTC, deed wrote:
 core.runtime's import path is specified in the sc.ini file, in 
 DFLAGS
 If I specify the core.runtime file in the build file everything 
 works

 Why is it so?
in short - it looks like phobos.lib not linked, try link it manually. i don't know why...
Nov 09 2013
parent reply "deed" <none none.none> writes:
On Saturday, 9 November 2013 at 15:49:40 UTC, evilrat wrote:
 On Saturday, 9 November 2013 at 15:30:55 UTC, deed wrote:
 core.runtime's import path is specified in the sc.ini file, in 
 DFLAGS
 If I specify the core.runtime file in the build file 
 everything works

 Why is it so?
in short - it looks like phobos.lib not linked, try link it manually. i don't know why...
No, it doesn't work. Do I have to compile my own runtime library and pass it on the command line? (Have just grabbed the 3.064.2.zip file and not run any installer.)
Nov 09 2013
parent reply "deed" <none none.none> writes:
On Saturday, 9 November 2013 at 15:56:12 UTC, deed wrote:
 On Saturday, 9 November 2013 at 15:49:40 UTC, evilrat wrote:
 On Saturday, 9 November 2013 at 15:30:55 UTC, deed wrote:
 core.runtime's import path is specified in the sc.ini file, 
 in DFLAGS
 If I specify the core.runtime file in the build file 
 everything works

 Why is it so?
in short - it looks like phobos.lib not linked, try link it manually. i don't know why...
No, it doesn't work. Do I have to compile my own runtime library and pass it on the command line? (Have just grabbed the 3.064.2.zip file and not run any installer.)
The readme file in the runtime directory says it's compiled into phobos64.lib, which I presume is passed successfully, otherwise there would have been more unresolved symbols..
Nov 09 2013
parent reply "evilrat" <evilrat666 gmail.com> writes:
On Saturday, 9 November 2013 at 15:59:02 UTC, deed wrote:
 No, it doesn't work. Do I have to compile my own runtime 
 library and pass it on the command line? (Have just grabbed 
 the 3.064.2.zip file and not run any installer.)
The readme file in the runtime directory says it's compiled into phobos64.lib, which I presume is passed successfully, otherwise there would have been more unresolved symbols..
better use installer, or you can try to set correct linker, mspdb dll, and lib paths in sc.ini for your visual c++ and windows sdk.
Nov 09 2013
parent reply "deed" <none none.none> writes:
On Saturday, 9 November 2013 at 16:08:15 UTC, evilrat wrote:
 On Saturday, 9 November 2013 at 15:59:02 UTC, deed wrote:
 No, it doesn't work. Do I have to compile my own runtime 
 library and pass it on the command line? (Have just grabbed 
 the 3.064.2.zip file and not run any installer.)
The readme file in the runtime directory says it's compiled into phobos64.lib, which I presume is passed successfully, otherwise there would have been more unresolved symbols..
better use installer, or you can try to set correct linker, mspdb dll, and lib paths in sc.ini for your visual c++ and windows sdk.
phobos64.lib contains _D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb but not _D4core7runtime7Runtime10initializeFZb Does this mean that the phobos64.lib is not aligned with current core.runtime module?
Nov 09 2013
parent reply "evilrat" <evilrat666 gmail.com> writes:
On Saturday, 9 November 2013 at 16:22:07 UTC, deed wrote:
 phobos64.lib contains
 _D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb
 but not
 _D4core7runtime7Runtime10initializeFZb

 Does this mean that the phobos64.lib is not aligned with 
 current core.runtime module?
i also have this problem on win 8.1 with visual studio 2013. smells like a bug for me. file a bug on tracker. for now i think manually calling rt_init() and rt_term() can be used to avoid it.
Nov 09 2013
next sibling parent reply "Palmic" <mpalomas live.fr> writes:
Same problem here.

Configuration: Windows 8.1, with 8.1 SDK, and visual studio 2013.

I tried to link manually phobos64 with no success. Anyway there 
is the windows page saying that WinMain automatically forces the 
compiler to link phobos.

What is even more strange is that if you take

Has a bug report been filled? Or any news regarding this issue?

By the way I'm using VisualD, going to check now if I get the 
same problem with command line.

On Saturday, 9 November 2013 at 16:46:36 UTC, evilrat wrote:
 On Saturday, 9 November 2013 at 16:22:07 UTC, deed wrote:
 phobos64.lib contains
 _D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb
 but not
 _D4core7runtime7Runtime10initializeFZb

 Does this mean that the phobos64.lib is not aligned with 
 current core.runtime module?
i also have this problem on win 8.1 with visual studio 2013. smells like a bug for me. file a bug on tracker. for now i think manually calling rt_init() and rt_term() can be used to avoid it.
Jan 05 2014
parent "Palmic" <mpalomas live.fr> writes:
Replying to myself:

In my case at lease, I don't think it's a bug...

I have just used the build tool binary that comes with the 
DWinProgramming samples, added a new folder with my source in the 
Samples directory, and the tool managed to build it properly...

I will now look at the souces of this build tool, seems like it's 
not using the same parameters/environment than my VisualD project.
Jan 05 2014
prev sibling parent reply "Erik van Velzen" <erik evanv.nl> writes:
It works if you recompile phobos64.lib

So it seems the standard DMD 2.064.2 download comes with an
outdated version of phobos64.lib which is out of sync with the
included source code.
Jan 05 2014
parent reply "Erik van Velzen" <erik evanv.nl> writes:
 Palmic the DWinProgramming samples use the overload

Runtime.initialize(ExceptionHandler)

Which gives a warning that it is deprecated and you should use 
this overload instead:

Runtime.initialize()

But this is not compiled in phobos64.lib, while it is included in 
the source code. So the library and source code are out of sync. 
Fortunately it is relatively easy to compile yourself.

I will make a bug report for this.
Jan 05 2014
parent reply "FreeSlave" <freeslave93 gmail.com> writes:
On Sunday, 5 January 2014 at 19:05:58 UTC, Erik van Velzen wrote:
  Palmic the DWinProgramming samples use the overload

 Runtime.initialize(ExceptionHandler)

 Which gives a warning that it is deprecated and you should use 
 this overload instead:

 Runtime.initialize()

 But this is not compiled in phobos64.lib, while it is included 
 in the source code. So the library and source code are out of 
 sync. Fortunately it is relatively easy to compile yourself.

 I will make a bug report for this.
I had similar issues (undefined reference) on Linux, but with Runtime.loadLibrary and Runtime.unloadLibrary, which call rt_loadLibrary and rt_unloadLibrary. I thought it's because of lack of proper dynamic loading support.
Jan 05 2014
parent reply "Erik van Velzen" <erik evanv.nl> writes:
Filed under "installer"

https://d.puremagic.com/issues/show_bug.cgi?id=11871

You could add the linux thing as a comment if you're sure it's 
the same issue.
Jan 05 2014
parent "FreeSlave" <freeslave93 gmail.com> writes:
On Sunday, 5 January 2014 at 19:30:46 UTC, Erik van Velzen wrote:
 Filed under "installer"

 https://d.puremagic.com/issues/show_bug.cgi?id=11871

 You could add the linux thing as a comment if you're sure it's 
 the same issue.
Well, I'm not sure this is same. I explored something new to me and better create another topic here.
Jan 05 2014