Project

General

Profile

Actions

Support #2146

closed

Wt::Dbo::Dbo & Linker

Added by Bud T over 11 years ago. Updated over 11 years ago.

Status:
Closed
Priority:
High
Assignee:
-
Target version:
-
Start date:
08/25/2013
Due date:
% Done:

0%

Estimated time:

Description

This problem arose as I was attempting to adapt the dbo-tutorial-1 code (almost verbatim) to a test project.

I can include these libs:

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>

...but trying to use them causes a linker error:

...
1>Link:
1>     Creating library C:\Users\User\Documents\Visual Studio 2010\Projects\app\Debug\app.lib and object C:\Users\User\Documents\Visual Studio 2010\Projects\st\Debug\Stapp.exp
1>App.obj : error LNK2019: unresolved external symbol "public: __thiscall Wt::Dbo::Session::~Session(void)" (??1Session`Dbo@Wt@@QAE`XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)
1>App.obj : error LNK2019: unresolved external symbol "public: __thiscall Wt::Dbo::Transaction::~Transaction(void)" (??1Transaction`Dbo@Wt@@QAE`XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)
1>App.obj : error LNK2019: unresolved external symbol "public: __thiscall Wt::Dbo::Transaction::Transaction(class Wt::Dbo::Session &)" (??0Transaction`Dbo@Wt@@QAE@AAVSession@12@`Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)
...

When adding the Sqlite binary to my filesystem, and linking to it in Visual Studio's Properties >> Configuration Properties >> Linker >> Input >> Additional Dependencies field as follows:

kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies);wtd.lib;wthttpd.lib;"C:\OpenSSL-Win32\lib\VC\ssleay32MDd.lib";"C:\OpenSSL-Win32\lib\VC\libeay32MDd.lib";"C:\libraries\lib\zlibstatd.lib";"C:\libraries\sqlite3.dll"

The following error is returned:

...
1>ClCompile:
1>  All outputs are up-to-date.
1>C:\libraries\sqlite3.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x470
1>
1>Build FAILED.
...

I don't see any version of 'sqlite3.lib' that could be used. I'm looking here: http://www.sqlite.org/download.html

I'm not even sure if this is the only problem to be addressed in trying to fix that LNK2019 error. Please advise.

Actions #1

Updated by Bud T over 11 years ago

Given that I've already successfully linked to wtd.lib in "C:\Program Files (x86)\WT\lib", and given that wtdbod.lib and wtdbosqlite3d.lib are in that folder, I'm not sure why the linking errors. From Linker >> General >> Additional Library Directories:

"C:\Program Files (x86)\boost\boost_1_47\lib";"C:\Program Files (x86)\WT\lib";"C:\OpenSSL-Win32\lib\VC"

These values have been used for a while now without problems.

Actions #2

Updated by Bud T over 11 years ago

If I reduce the problem code (which is the run() definition) down to one line:

#include <Wt/Dbo/Dbo>
#include <Wt/Dbo/backend/Sqlite3>
#include <string>

namespace dbo = Wt::Dbo;

/*****
 * Dbo tutorial section 2. Mapping a single class
 *****/

class User {
public:
  enum Role {
    Visitor = 0,
    Admin = 1,
    Alien = 42
  };

  std::string name;
  std::string password;
  Role        role;
  int         karma;

  template<class Action>
  void persist(Action& a)
  {
    dbo::field(a, name,     "name");
    dbo::field(a, password, "password");
    dbo::field(a, role,     "role");
    dbo::field(a, karma,    "karma");
  }
};

void run()
{
  // * Dbo tutorial section 3. A first session
  dbo::backend::Sqlite3 sqlite3(":memory:");
}

I get these linker errors:

1>Link:
1>     Creating library C:\Users\User\Documents\Visual Studio 2010\Projects\app\Debug\App.lib and object C:\Users\User\Documents\Visual Studio 2010\Projects\app\Debug\App.exp
1>App.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall Wt::Dbo::backend::Sqlite3::~Sqlite3(void)" (??1Sqlite3`backend@Dbo@Wt@@UAE`XZ) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)
1>App.obj : error LNK2019: unresolved external symbol "public: __thiscall Wt::Dbo::backend::Sqlite3::Sqlite3(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0Sqlite3`backend@Dbo@Wt@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@`Z) referenced in function "void __cdecl run(void)" (?run@@YAXXZ)
1>C:\Users\User\Documents\Visual Studio 2010\Projects\app\Debug\App.exe : fatal error LNK1120: 2 unresolved externals
Actions #3

Updated by Bud T over 11 years ago

After adding these files to Linker >> Input >> Additional Dependencies:

...;"C:\Program Files (x86)\WT\bin\wtd.dll";"C:\Program Files (x86)\WT\bin\wtdbod.dll"

I got these similar errors:

...
2>ManifestResourceCompile:
2>  All outputs are up-to-date.
2>C:\Program Files (x86)\WT\bin\wtd.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x318
2>
2>Build FAILED.
...

The files were generated by the Wt installation, so I don't know the reason for this failure.

Actions #4

Updated by Wim Dumon over 11 years ago

  • Status changed from New to Resolved

Do not add .dll files to Linker >> Input >> Additional Dependencies. You always link against .lib files, never against .dll files. The dll files are required when you execute the executable, not when you link it.

You should indeed add wtdbod.lib and wtdbosqlite3d.lib to your Additional Dependencies. (or without the d suffix for release builds).

wtdbod.lib contains the symbols for dbo, wtdbosqlite3d.lib contains the sqlite3 backend. This includes sqlite itself, so no need to download anything from sqlite.org.

BR,

Wim.

Actions #5

Updated by Bud T over 11 years ago

Ok, thank you. Problem solved.

Actions #6

Updated by Wim Dumon over 11 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF