cancel
Showing results for 
Search instead for 
Did you mean: 

link failure on MSVC

06-10-2026 9:38 PM
oneeyeman1 Participant
665 views 8 comments
SAP Managed Tags
Subscribe

Hi,

As directed in one of my previous questions in order to get SQL Anywhere SDK for Windows I downloaded the full server package and iinstalled it on my development machine.

 

I then added the project  to my MSVC solution, add some code and then looking at the samples\build.bat I modified the options as follows:

 

C/C++ options:

/GS /analyze- /W4 /Zc:wchar_t /I"C:\Program Files (x86)\Visual Leak Detector\include" /I"..\dbinterface" /I"C:\Program Files\SQL Anywhere 17\SDK\include" /Zi /Gm- /Od /Fd"vc_mswuddll\sqlany_dll.pdb" /Zc:inline /fp:precise /D "__MEMORYLEAKS__" /D "WIN32" /D "_USRDLL" /D "DLL_EXPORTS" /D "_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE=1" /D "_CRT_NON_CONFORMING_SWPRINTFS=1" /D "_SCL_SECURE_NO_WARNINGS=1" /D "_SACAPI_VERSION=6" /D "_UNICODE" /D "MY_DLL_BUILDING" /D "_WINDLL" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MDd /FC /Fa"vc_mswuddll\" /EHsc /nologo /Fo"vc_mswuddll\" /Fp"vc_mswuddll\sqlany_dll.pch" /diagnostics:classic

 

Linker options:

/OUT:"..\dbhandler\vc_mswuddll\sqlany.dll" /MANIFEST /NXCOMPAT /PDB:"vc_mswuddll\sqlany_dll.pdb" /DYNAMICBASE "vld.lib" "dbinterface.lib" "user32.lib" "gdi32.lib" "advapi32.lib" "dbcapi.lib" "kernel32.lib" "winspool.lib" "comdlg32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"vc_mswuddll\sqlany_dll.lib" /DEBUG /DLL /MACHINE:X86 /SAFESEH /INCREMENTAL /PGD:"C:\Users\Igor\OneDrive\Documents\dbhandler_app\libsqlany\vc_mswuddll\sqlany_dll.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"vc_mswuddll\sqlany_dll.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"..\dbhandler\Debug" /LIBPATH:"C:\Program Files\SQL Anywhere 17\SDK\Lib\X86" /LIBPATH:"C:\Program Files (x86)\Visual Leak Detector\lib\Win32" /TLBID:1

 

Trying to build it I received the following:

1> database_sqlany.obj : error LNK2019: unresolved external symbol "int __cdecl sqlany_initialize_interface(struct SQLAnywhereInterface *,char const *)" (?sqlany_initialize_interface@@YAHPAUSQLAnywhereInterface@@PBD@Z) referenced in function "public: __thiscall SQLAnyDatabase::SQLAnyDatabase(int,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0SQLAnyDatabase@@QAE@HABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
1> database_sqlany.obj : error LNK2019: unresolved external symbol "void __cdecl sqlany_finalize_interface(struct SQLAnywhereInterface *)" (?sqlany_finalize_interface@@YAXPAUSQLAnywhereInterface@@@Z) referenced in function "public: __thiscall SQLAnyDatabase::SQLAnyDatabase(int,class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > const &)" (??0SQLAnyDatabase@@QAE@HABV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z)
1> ..\dbhandler\vc_mswuddll\sqlany.dll : fatal error LNK1120: 2 unresolved externals

 

What am I missing?

 

Thank you,

P.S.:

In my code I follow the sample code which have:

[code]

if( !sqlany_initialize_interface( &api, NULL ) ) {
printf( "Could not initialize the interface!\n" );
exit( 0 );
}

if( !api.sqlany_init( "MyAPP", SQLANY_API_VERSION_1, &max_api_ver )) {
printf( "Failed to initialize the interface! Supported version = %d\n", max_api_ver );
sqlany_finalize_interface( &api );
return -1;
}

/* A connection object needs to be created first */
sqlany_conn = api.sqlany_new_connection();

[/code]

 

Accepted Solutions (0)

Answers (1)

Answers (1)

chris_keating
Product and Topic Expert
Product and Topic Expert
0 Likes

Use the static library.  To do so, do not use the sacapidll.* files but include the sacapi.h header only. You are already referencing the static library dbcapi.lib in the linker options.  Additionally, you will not use the SQLAnywhereInterface in code.  As a result, don't call sqlany_initialize_interface or sqlany_finalize_interface methods. Additionally, the other APIs can be invoked as is, for example, the  api.sqlany_init would get called without the api. Your code snippet would be rewritten as:

if( !sqlany_init( "MyAPP", SQLANY_API_VERSION_1, &max_api_ver )) {
    printf( "[ERROR] Failed to initialize the interface! Supported version = %d\n", max_api_ver );
    exit( EXIT_FAILURE );
}

/* A connection object needs to be created first */
sqlany_conn = sqlany_new_connection();
if( sqlany_conn ) {

 

 

jack_schueler
Product and Topic Expert
Product and Topic Expert
I see this in your output "/LIBPATH:"C:\Program Files\SQL Anywhere 17\SDK\Lib\X86". Are you really building a 32-bit application?
chris_keating
Product and Topic Expert
Product and Topic Expert
0 Likes

A discussion today pointed out that the sacapidll.c  can be compiled without requiring it to be UNICODE. I don't use MSVC IDE for development but just the command link cl and link executables but here is an example batch that compiles the DBCAPI connecting.cpp example as UNICODE (see __MCUNICODE definition)  and the sacapidll.c without UNICODE .  You can likely do the same in MSVC but I leave that as an exercise to the reader. 

setlocal

set __MCOPTS={compiler options excluding UNICODE}
set __MCUNICODE=/D_UNICODE /DUNICODE
set __LNKOPTS={linker options}

cl %__MCOPTS% %__MCUNICODE% -c /Tp connecting.cpp
cl %__MCOPTS% -c /Tp %SQLANY17%\SDK\dbcapi\sacapidll.c
link /out:connect%PLAT_EXT%.exe connecting.obj sacapidll.obj %__LNKOPTS%

endlocal