Linker Error with Berkeley DB and Visual C++

481 views Asked by At

HI I'm an internship student and my job is porting a program from linux c to visual c. I've to use Berkeley DB and Visual C++. after trying for a while, i get the linking error

berkeleyDB.obj : error LNK2019: unresolved external symbol "int __cdecl database_select_end(unsigned int,unsigned int,struct chunk * const,int)" (?database_select_end@@YAHIIQAUchunk@@H@Z) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk@@YAXIPAIH@Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "void __cdecl database_sync(void)" (?database_sync@@YAXXZ) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk@@YAXIPAIH@Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "void __cdecl database_insert_bluk(struct chunk *,int)" (?database_insert_bluk@@YAXPAUchunk@@H@Z) referenced in function "void __cdecl op_ds_bulk(unsigned int,unsigned int *,int)" (?op_ds_bulk@@YAXIPAIH@Z)
berkeleyDB.obj : error LNK2019: unresolved external symbol "int __cdecl database_open(int,char *)" (?database_open@@YAHHPAD@Z) referenced in function _main

no idea what are those, pls help me

1

There are 1 answers

2
Rup On

They're C++-mangled (or 'decorated') function names. C++ allows function overloading - multiple functions with the same name but with different parameter signatures - and so it needs to encode the parameters etc. into the function name to differentiate the multiple overloads at link time. Most likely your DB library was built as C and won't have decorated names.

Try wrapping your db.h include in an extern "C"

extern "C"
{
    #include <db/db.h>
}

to tell the compiler to treat the API as C functions, not C++.

(It looks like you've got a typo in there too: database_insert_bluk not _bulk.)

Alternatively, it looks like Berkeley DB ship a C++ interface #include <db/db_cxx.h> you could use instead, although if you're porting code it may be easier to stick to the C interface. The difference is probably that the Linux code you're porting was compiled as C whereas here you're compiling it as C++.

From the other comment you've posted: if your problem is that you're actually not linking in Berkeley DB at all then you'll need to go into project settings (right-click on the project name), the C++ link tab, and then add the .lib file to the list of libraries to link into your project. You may need to specify the path to find this too, and you should do this for both debug and release modes (the drop down at the top of the settings).