Thread overview
Linking phobos64.lib errors
Sep 03, 2014
Szymon Gatner
Sep 03, 2014
Rikki Cattermole
Sep 03, 2014
Szymon Gatner
September 03, 2014
Hi,

I am trying to make simple x64 C++ application that uses D static library (trying to do "Interfacing with C++" from "D Cookbook" chapter). I am Using Visual Studio 2012 to create main() like this:

#include <iostream>

extern "C" int rt_init();
extern "C" void rt_term();
// RAII struct for D runtime initialization and termination
struct DRuntime {
  DRuntime() {
    if(!rt_init()) {
      // you could also use an exception
      fprintf(stderr, "D Initialization failed");
      exit(1);
    }
  }
  ~DRuntime() {
    rt_term();
  }
};

int main()
{
  DRuntime druntime;
}

and then I am just setting linker to link to phobos64.lib but I am getting those:

1>phobos64.lib(dmain2_4ec_2f9.obj) : error LNK2019: unresolved external symbol _deh_beg referenced in function rt_init
1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2001: unresolved external symbol _deh_beg
1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved external symbol _minfo_end referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved external symbol _minfo_beg referenced in function _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2019: unresolved external symbol _deh_end referenced in function _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable

What am I doing wrong? Book says that on x64 Windows VC++ can be used to create hybrid application.
September 03, 2014
On 3/09/2014 7:22 p.m., Szymon Gatner wrote:
> Hi,
>
> I am trying to make simple x64 C++ application that uses D static
> library (trying to do "Interfacing with C++" from "D Cookbook" chapter).
> I am Using Visual Studio 2012 to create main() like this:
>
> #include <iostream>
>
> extern "C" int rt_init();
> extern "C" void rt_term();
> // RAII struct for D runtime initialization and termination
> struct DRuntime {
>    DRuntime() {
>      if(!rt_init()) {
>        // you could also use an exception
>        fprintf(stderr, "D Initialization failed");
>        exit(1);
>      }
>    }
>    ~DRuntime() {
>      rt_term();
>    }
> };
>
> int main()
> {
>    DRuntime druntime;
> }
>
> and then I am just setting linker to link to phobos64.lib but I am
> getting those:
>
> 1>phobos64.lib(dmain2_4ec_2f9.obj) : error LNK2019: unresolved external
> symbol _deh_beg referenced in function rt_init
> 1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2001: unresolved
> external symbol _deh_beg
> 1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved
> external symbol _minfo_end referenced in function
> _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
> 1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved
> external symbol _minfo_beg referenced in function
> _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
> 1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2019: unresolved
> external symbol _deh_end referenced in function
> _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable
>
>
> What am I doing wrong? Book says that on x64 Windows VC++ can be used to
> create hybrid application.

My gut feeling looking at that, is that its not linking against the c runtime.

For reference I'm pretty sure _deh_beg is related to exception handling.
September 03, 2014
On Wednesday, 3 September 2014 at 08:47:35 UTC, Rikki Cattermole wrote:
> On 3/09/2014 7:22 p.m., Szymon Gatner wrote:
>> Hi,
>>
>> I am trying to make simple x64 C++ application that uses D static
>> library (trying to do "Interfacing with C++" from "D Cookbook" chapter).
>> I am Using Visual Studio 2012 to create main() like this:
>>
>> #include <iostream>
>>
>> extern "C" int rt_init();
>> extern "C" void rt_term();
>> // RAII struct for D runtime initialization and termination
>> struct DRuntime {
>>   DRuntime() {
>>     if(!rt_init()) {
>>       // you could also use an exception
>>       fprintf(stderr, "D Initialization failed");
>>       exit(1);
>>     }
>>   }
>>   ~DRuntime() {
>>     rt_term();
>>   }
>> };
>>
>> int main()
>> {
>>   DRuntime druntime;
>> }
>>
>> and then I am just setting linker to link to phobos64.lib but I am
>> getting those:
>>
>> 1>phobos64.lib(dmain2_4ec_2f9.obj) : error LNK2019: unresolved external
>> symbol _deh_beg referenced in function rt_init
>> 1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2001: unresolved
>> external symbol _deh_beg
>> 1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved
>> external symbol _minfo_end referenced in function
>> _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
>> 1>phobos64.lib(sections_win64_57b_5a5.obj) : error LNK2019: unresolved
>> external symbol _minfo_beg referenced in function
>> _D2rt14sections_win6414getModuleInfosFZAyPS6object10ModuleInfo
>> 1>phobos64.lib(sections_win64_575_4e2.obj) : error LNK2019: unresolved
>> external symbol _deh_end referenced in function
>> _D2rt14sections_win6412SectionGroup8ehTablesMxFNdZAyS2rt15deh_win64_posix9FuncTable
>>
>>
>> What am I doing wrong? Book says that on x64 Windows VC++ can be used to
>> create hybrid application.
>
> My gut feeling looking at that, is that its not linking against the c runtime.
>
> For reference I'm pretty sure _deh_beg is related to exception handling.

Hey, for some reason I missed this:

http://forum.dlang.org/thread/ji93fh$15ph$1@digitalmars.com

The fix is to add main() function to D library. Don't know why it is needed for static lib but it sure helps to resolve link issues.